Search code examples
htmlasp.net-mvcformshiddenfieldhttp-post

Is there a way to not post the model value of the hiddenfield?


I have set of hiddenfields in my form to post the values of the read-only fields. But in some circumstances I wouldn't need to post the values. For example:

<div style="display: none;">
<!-- read-only controls -->
@Html.DisplayFor(model=>model.DeviceName)
@Html.HiddenFor(model=>model.DeviceName)
</div>

In the above example, I have hidden the above div using JQuery, but the value of the hiddenfield within the div is still posted.


Solution

  • You need to make the input disabled. Disabled inputs do not get submitted to server