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 ofModel.Id. Remove the double quotes also. The below code should work.And Why are you giving a css class to a hidden field ?