I have following hidden input:
<input type="hidden" class="deleted" name="Deleted" data-id="@Model.Id" value="@Model.Deleted" />
I was wanting to convert this to the MVC helper HiddenFor.
Got this far:
@Html.HiddenFor(x => x.Deleted, new { @class="deleted" })
So that covers the class. I also need the data-id attribute and value.
Tried to add the data-id as:
@Html.HiddenFor(x => x.Deleted, new { @class="deleted", data-id="@Model.Id" })
Well the helper doesn't seem to like the hyphen in the data-id.
So how to get it in there?
Also how to get the value="@Model.Deleted"
in there also?
Use _
and MVC will convert that to -
when rendering.
Also you do not need the @
infront of Model.Id
. Remove the double quotes also. The below code should work.
@Html.HiddenFor(x => x.Deleted, new { @class="deleted", data_id=Model.Id })
And Why are you giving a css class to a hidden field ?
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