【问题标题】:Applying css on ActionLink in mvc?在 mvc 中的 ActionLink 上应用 css?
【发布时间】:2014-04-29 05:30:48
【问题描述】:

我在 mvc5 中工作。我使用这种语法在视图中创建了一个简单的操作链接

@Html.ActionLink("Manage List", "Index", new { @class = "ManageLink" });

但是在我添加控制器名称之前,css 无法正常工作:

@Html.ActionLink("Manage List", "Index",new { controller = "ControllerName" }, new { @class = "ManageLink" });

我想知道为什么我们需要在这里定义控制器名称,而很明显每个视图都与控制器的某些操作方法相关?我对 mvc 很陌生,所以需要知道这些东西。

感谢您的帮助。

【问题讨论】:

    标签: css asp.net-mvc-5 html-helper


    【解决方案1】:

    您也可以通过简单地指定要设置的可选参数的名称来解决此问题:

    @Html.ActionLink("Manage List", "Index", htmlAttributes: new { @class = "ManageLink" });
    

    否则,Razor 引擎必须尝试找出您尝试调用的 ActionLink 方法的哪个重载;听起来在您的情况下,它认为第三个参数是针对 routeValues 参数的。

    这也可以:

    @Html.ActionLink("Manage List", "Index", "ControllerNameHere", new { @class = "ManageLink" });
    

    【讨论】:

      猜你喜欢
      • 2012-01-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-08-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多