ActionLinks
,view
上有更多MVC project
我需要根据ViewBag
值启用/禁用这些按钮。
我已在视图中添加了此代码
@{
if (ViewBag.ModifyOS)
{
@Html.ActionLink(@Resources.Common.ModifyOSTerms, "ModifyOSTerms", "Document", new { lotId = LotId }, new { @class = "btn btn-success disabled" })
}
else
{
@Html.ActionLink(@Resources.Common.ModifyOSTerms, "ModifyOSTerms", "Document", new { lotId = LotId }, new { @class = "btn btn-success" })
}
}
这样可以正常工作,但是我想以更优雅的方式实现这一目标。 我已经尝试过这种方式:
@{
string Disabled = "";
if (ViewBag.ModifyOS)
{
Disabled = "disable";
}
}
并且我已将此Disabled
设置为ActionLink
@Html.ActionLink(@Resources.Common.ModifyOSTerms, "ModifyOSTerms", "Document", new { lotId = LotId }, new { @class = "btn btn-success" , disabled = "@Disabled" })
我已经尝试过这种方式:
@Html.ActionLink(@Resources.Common.ModifyOSTerms, "ModifyOSTerms", "Document", new { lotId = LotId }, new { @class = "btn btn-success" , disabled = "@(ViewBag.ModifyOS)" })
但是在两种情况下,按钮始终处于禁用状态。
答案 0 :(得分:1)
看起来您可以通过添加disable
类来处理禁用问题。为什么不选择它呢?
string cssClass = "btn btn-success";
if (ViewBag.ModifyOS)
{
cssClass += " disabled";
}
@Html.ActionLink(@Resources.Common.ModifyOSTerms, "ModifyOSTerms", "Document", new { lotId = LotId }, new { @class = @cssClass })