@Html.HiddenFor(model => model.JobIndicator)
The value for JobIndicator doesn't get refreshed after submitting the page.
I can see the value getting updated when I have it in the display field.
A hidden field lets web developers include data that cannot be seen or modified by users when a form is submitted. A hidden field often stores what database record that needs to be updated when the form is submitted.
If you refresh the page or click on a hyperlink that does a GET, then the value will be lost or revert to the designer-generated default. Back to your question, if you have a designer-generated HiddenField (in the aspx file), it should automatically set the value on postback.
HiddenFor<TModel,TProperty>(HtmlHelper<TModel>, Expression<Func<TModel,TProperty>>, IDictionary<String,Object>) Returns an HTML hidden input element for each property in the object that is represented by the specified expression, using the specified HTML attributes.
The Form Fields which are created using Model class are cleared by clearing the Model using ModelState. Clear function. int personId = person.
Put this in your controller :
ModelState.Remove("JobIndicator");
Then your hidden field will be updated.
The problem is Html helpers get data from ModelState
and not from model you pass when you call post action.To solve this, you can call ModelState.Clear()
in the post action before you return your view, this way the info in the ModelState
is going to be cleared and repopulated once your view is regenerated.
You can find more info about this issue (and other solutions) in this blog
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