2013-03-19 71 views
0

如何在此處添加班級名稱?在Html.ActionLink中添加班級

Html.ActionLink(
     item.Name, 
     "GetProducts", 
     "Products", 
     new { CityName = item.CityName.UnderScore(), CategoryName = item.Name.UnderScore() }, 
     null); 

謝謝。

回答

2

使用此Html.ActionLink重載方法

public static MvcHtmlString ActionLink(
    this HtmlHelper htmlHelper, 
    string linkText, 
    string actionName, 
    string controllerName, 
    RouteValueDictionary routeValues, 
    IDictionary<string, Object> htmlAttributes 
) 

你的榜樣

Html.ActionLink(
    item.Name, 
    "GetProducts", 
    "Products", 
    new { CityName = item.CityName.UnderScore(), CategoryName = item.Name.UnderScore() }, 
    new { @class="some_class" }); 
+1

使用'@'符號是如何使用任何C#的關鍵字爲除關鍵字以外的東西。大多數時候人們會試圖命名它,但在像這樣的情況下,它必須被稱爲'class'(由於它映射到HTML屬性),用'@'作爲前綴是你唯一的選擇。 – 2013-03-19 16:21:08