P.B*_*key 4 c# razor asp.net-mvc-3
如何在ActionLink中动态设置@class?
我想要做
@Html.ActionLink("Pricing", "Index", "Pricing", new { PageIndex = 2, @(ViewBag.PageIndex == 2 ? @class="" : @class="ActiveMenuItem" )}, null)
Run Code Online (Sandbox Code Playgroud)
但是运行时会破坏我的语法.
假设您希望"class"成为HTML属性并将"PageIndex"作为操作参数,则可以执行以下操作:
<a href="@Url.Action("Index", "Pricing")?PageIndex=2" class="@(ViewBag.PageIndex == 2 ? "ActiveMenuItem" : "")">Pricing</a>
Run Code Online (Sandbox Code Playgroud)
MUSEFAN编辑:
你仍然可以像这样使用ActionLink ......
@Html.ActionLink("Pricing", "Index", "Pricing", new {PageIndex = 2}, new {@class = ViewBag.PageIndex == 2 ? "" : "ActiveMenuItem"})
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2665 次 |
| 最近记录: |