I’m trying to dynamically set the disabled attribute for the TextBoxFor HtmlHelper
@Html.TextBoxFor(model => model.Street,
new
{
@class = "",
disabled = (Model.StageID==(int)MyEnum.Sth) ? "disabled" : ""
})
but even if there is disabled="" it is the same as disabled="disabled". How to get around of this ?
I have the same problem about month ago and I finished by using this extension method for it
And after that you can use it like this
EDIT (after Paul‘s comment):
The using of
data-xxxhtml attributes may be mined by using the constructor of the System.Web.Routing.RouteValueDictionary class, since underscores will not be automatically converted to minus sign.Use the method System.Web.Mvc.HtmlHelper.AnonymousObjectToHtmlAttributes instead: will solve this issue.
UPDATED CODE (Extension method body only)