Firefox caches hidden inputs even when autocompletion is turned off

I have a form with the autocomplete attribute set to off .

Inside this form there is a hidden input element (generated using the ASP.NET MVC Html.HiddenFor() method, but this should be irrelevant):

 <input type="hidden" value="0" name="Status" id="Status" data-val-required="The Status field is required." data-val-number="The field Status must be a number." data-val="true"> 

When the form is submitted, this value is incremented by one, and the model returns to the view. If I write the status value on the page, I see that the value has been correctly increased.

However, this hidden input field is always cached. He never gets the right meaning. I tried to set the autocomplete attribute directly on the input element, but without success.

How can I get this hidden field to get the correct value? I would prefer not to use Javascript.

Edit : providing more code ...

controller

 //This code is being executed, and the status is being incremented. shippingOrder.Status = (shippingOrder.Status != (int)OrderStatus.Closed) ? shippingOrder.Status + 1 : shippingOrder.Status; 

View

 @using (Html.BeginForm("Number", "Order", FormMethod.Post, new { id = "orderSummary", autocomplete = "off" })) { ... @Html.HiddenFor(m => m.Status) } 
+4
source share
1 answer

According to this post here html helpers like HiddenFor will always use the published value first and then the value in the model.

As you said, when you write a value to a page, you can see that it is increasing, but the helper uses the previously published value, which is the intended behavior.

The link suggests using ModelState.Remove("Status") or ModelState.Clear() before assigning a new value.

It is also assumed that another option might not use the HiddenFor , but instead create a hidden field itself. Similar to this:

<input type="hidden" name="Status" value="@Model.Status" />

In any case, your problem seems to be based on similar circumstances.

+3
source

Source: https://habr.com/ru/post/1411402/


All Articles