2013-03-19 82 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