Frage

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.

Best regards

War es hilfreich?

Lösung

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

@Html.ActionLink("Home", "Index", "Home", null, new { @class = @ViewBag.myClass})
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top