2012-04-30 52 views
1

我想用剃刀語法複製下面的HTML:如何將此html轉換爲剃鬚刀?

<a href="index.html" data-description="I Want This Description">Home</a> 

我知道我會的鏈接做到這一點:

@Html.ActionLink("Home", "Index", "Home") 

我怎麼想補充一點,就是上面的HTML標籤內的信息「data-description =」我要這個描述「」?

+0

[ASP.NET MVC2 Razor -Html.ActionLink with HTML Attribute]的可能重複(http://stackoverflow.com/questions/7962477/asp-net-mvc2-razor-html-actionlink-with-html-attribute ) – Ben

回答

1

您可以通過添加一個包含匿名對象的參數來添加html屬性,該對象包含所需的屬性和值。

@Html.ActionLink("Home", "Index", "Home", new { data_description = "I want this desription" }) 

請注意下劃線而不是連字符。顯示視圖時,MVC自動用連字符替換下劃線。