Disabled form inputs do not appear in the request

后端 未结 11 2009
暗喜
暗喜 2020-11-22 04:37

I have some disabled inputs in a form and I want to send them to a server, but Chrome excludes them from the request.

Is there any workaround for this without addin

11条回答
  •  萌比男神i
    2020-11-22 05:03

    To post values from disabled inputs in addition to enabled inputs, you can simply re-enable all of the form's inputs as it is being submitted.

    If you prefer jQuery:

    For ASP.NET MVC C# Razor, you add the submit handler like this:

    using (Html.BeginForm("ActionName", "ControllerName", FormMethod.Post,
        // Re-enable all input elements on submit so they are all posted, even if currently disabled.
        new { onsubmit = "this.querySelectorAll('input').forEach(i => i.disabled = false)" } ))
    {
        
    }
    

提交回复
热议问题