ASP.NET MVC: generating action link with custom html in it
Asked Answered
S

2

8


How can I generate action link with custom html inside.
Like following:
<a href="http://blah-blah/.....">
<span class="icon"/> New customer
</a>

Sheng answered 7/10, 2010 at 7:31 Comment(0)
C
9

You can use the UrlHelper class :

<a href="<% =Url.Action("Create","Customers") %>">
    <span class="icon"/> New customer
</a>

The MSDN link is here : http://msdn.microsoft.com/en-us/library/system.web.mvc.urlhelper.aspx

Carranza answered 7/10, 2010 at 7:33 Comment(2)
o, it is much obvious, that I thought :) Thanks!Sheng
BTW, I've found some helpful info here: stephenwalther.com/blog/archive/2009/03/03/… and here iridescence.no/post/…Sheng
A
0

For newer versions of .net,

replace

 href="<% =Url.Action("Create","Customers") %>"

with

href="@Url.Action("Create","Customers")"

to give something like

<a href="@Url.Action("Create","Customers")">
   <span class="icon"/> New customer 
</a>
Arboreous answered 24/4, 2020 at 16:13 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.