Condition Of Html Helper Not Working
I want the disabled attribute be added to a textbox based on a condition @Html.TextBoxFor(m => m.kidsNumber, new { (Model.kidsDropDown != '2') ? '@disabled' : ''})
Solution 1:
You have not said which attribute you want to set ::
you code is without attribute and you should use use readonly instead because disabled fields are not posted on form submit
@Html.TextBoxFor(m => m.kidsNumber, new { (Model.kidsDropDown != "2") ? "@disabled" : ""})
For Disabled attribute Use::
@Html.TextBoxFor(m => m.kidsNumber, Model.kidsDropDown != "2" ? new {disabled = "disabled"} : null )
For readonly Use something like::
@Html.TextBoxFor(m => m.kidsNumber, new { @readonly= (Model.kidsDropDown != "2" ? "readonly" : "")})
Post a Comment for "Condition Of Html Helper Not Working"