这是我的假模型:
class Customer {
string Name;
// View Model part
bool IsDisabled;
}
以下是我的观点:
@using (Html.BeginForm(actionName, controllerName))
{
@Html.TextBoxFor( c => c.Name, new { disabled = ***) })
<input type="submit" value="Submit" />
}
所以问题是:如何将viewmodel的'isDisabled'属性绑定到文本框的'disabled'属性?即什么应该代替' * '?
答案 0 :(得分:2)
@Html.TextBoxFor(c => c.Name, Model.IsDisabled ? new { disabled = "disabled" } : null)
答案 1 :(得分:1)
@Html.TextBoxFor( c => c.Name, new { disabled = c.IsDisabled) })