I have tried to insert a string variable inside a textboxfor to complete his parameters, but the result is something as variablename=.....
For example, if I want disable the textbox depending on boolean in the modelview :
@string isDisabled = (Model.kbinding_boolvar ? "disabled" : "");
@Html.TextBoxFor(m => m.kbinding_namevar, new { @class = "classname", @is_disabled })
The html output is this :
<input class="classname" isDisabled="disabled" data-val="true" name="kbinding_textbox_name" type="text" value="" />
instead of :
<input class="classname" disabled data-val="true" name="kbinding_textbox_name" type="text" value="" />
What's the correct syntax to use to achieve the result?
@Html.TextBoxFor(m => m.kbinding_namevar, new { @class = "classname", disabled = is_disabled})what happens is, asp.net mvc is taking the attribute and value i.e both asis_disabled. You have to explicitly say the attribute name. Alternativey you can name your variable asdisabledand then you don't need an explicit attribute name