MVC剃刀布局 - 从视图修改

时间:2022-09-12 15:12:47

This is my layout page:

这是我的布局页面:

<!doctype html>
<html lang="en">
<head>
    <meta charset='utf-8'>
    <title>@ViewBag.Title</title>
</head>
<body>       
    @Html.ActionLink("Home", "Index", "Home", null, new { @class = "selected"})
    @Html.ActionLink("Users", "Index", "User")
    @Html.ActionLink("Customers", "Index", "ProductCompany")

    @RenderBody()
</body>
</html>

I would like to modify actionlink "selected" class depending on the loaded view on the server side. I am looking for options available to do it.

我想修改actionlink“selected”类,具体取决于服务器端加载的视图。我正在寻找可用的选项。

Best regards

最好的祝福

1 个解决方案

#1


1  

I think you could send the class name in the ViewBag and set it as below;

我想你可以在ViewBag中发送类名并将其设置如下;

@Html.ActionLink("Home", "Index", "Home", null, new { @class = @ViewBag.myClass})

#1


1  

I think you could send the class name in the ViewBag and set it as below;

我想你可以在ViewBag中发送类名并将其设置如下;

@Html.ActionLink("Home", "Index", "Home", null, new { @class = @ViewBag.myClass})