html - Add property with - in name -
in mvc using html.textboxfor()
control
i have input type control below.
<input id="phonenumber" type="text" class="phonenumber form-control" value="@actorphone.phonenumber" data-phonetype ="@actorphone.phonetypetd" data-actorid ="@model.actorid" maxlength="30"/>
i want change intput control mvc
@html.textboxfor(m=>m.phonenumber,new {@class = "phonenumber", maxlength = "30"})
how can add data-phonetype , data-actorid properties html control, - not allowed in properties of html attribute
.
use underscore _
the razor engine smart enough render underscore within property name corresponding dash sign, resulting in desired html5-like attributes
example:
@html.textboxfor(m=>m.phonenumber, new {@class = "phonenumber", maxlength = "30", data_phonetype = your_value_here, data-actorid=your_value_here })
and should result in desired output.
hope helps :)
Comments
Post a Comment