Asp.net-Mvc

ASP.NET MVC:生成帶有自定義 html 的操作連結

  • April 24, 2020

如何生成內部帶有自定義 html 的操作連結。

如下:

`<a href=“http://blah-blah/…..">

<span class=“icon”/> New customer

</a>`

您可以使用 UrlHelper 類:

&lt;a href="&lt;% =Url.Action("Create","Customers") %&gt;"&gt;
   &lt;span class="icon"/&gt; New customer
&lt;/a&gt;

MSDN 連結在這裡:http: //msdn.microsoft.com/en-us/library/system.web.mvc.urlhelper.aspx

對於較新版本的 .net,

代替

href="&lt;% =Url.Action("Create","Customers") %&gt;"

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

給予類似的東西

&lt;a href="@Url.Action("Create","Customers")"&gt;
  &lt;span class="icon"/&gt; New customer 
&lt;/a&gt;

引用自:https://stackoverflow.com/questions/3879547