在asp.net mvc razor

时间:2017-05-02 10:15:36

标签: asp.net-mvc razor

我想在asp.net mvc razor

中禁用编辑模式下的DropDownList

我有这段代码:

 @Html.DropDownListFor(m => m.FK_TypeID, new List<SelectListItem> { new SelectListItem { Text = "Select", Value = "", Selected = true } }, new { @class = "form - control" })

如何实现它

2 个答案:

答案 0 :(得分:0)

如果你知道视图何时处于编辑模式,那应该不难。请参考以下内容:

@if(isEditMode == true)
{
@Html.DropDownListFor(m => m.FK_TypeID, new List<SelectListItem> { new SelectListItem { Text = "Select", Value = "", Selected = true } }, new { @class = "form - control",@disabled="disabled" })
}
else{
@Html.DropDownListFor(m => m.FK_TypeID, new List<SelectListItem> { new SelectListItem { Text = "Select", Value = "", Selected = true } }, new { @class = "form - control" })
}

这是你想要达到的目标吗?

答案 1 :(得分:0)

我使用

找到了一个更短的解决方案
RewriteEngine on
RewriteBase /
RewriteRule ^sandbox/htaccess/one\.php$ /sandbox/htaccess/two.php? [L,R=301]

借助此链接 Conditional html attribute with Html Helper