I want to know how write HTML Helper like @Html.TextBoxFor(model => model.signature)
to have data-id
parameter in produced input like below by helper.
<input type="text" name="signature" data-id="No Signature" />
Note 1: parameter like dataId
is work by htmlAttributes
because it is a simple variable.
Note 2: I know extended method and use attribute like @{var attributes = new Dictionary<string, object>{{ "data-id", "No Signature" }};}
I feel that there must be a better way to solve this. Any idea...?
Thanks a lot.
You can add data-
attributes this way:
@Html.TextBoxFor(model => model.signature, new { data_id = "No signature" })
You have to use underscores (_
) in stead of dashes (-
).
Tip: it's also possible to use Model
variables in your data-
attributes:
new { data_id = Model.Id }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With