Setting EditorFor from ajax results
I have a form that has fields that I'd like to update from an ajax call. The form has the user fill in a few fields and then allows them to click a button which makes an ajax call and returns data back from the controller. I'm able to update the data that's visible in this block: @Html.EditorFor(o => o.Mileage) when debugging by using this in the response of the ajax call: $('#Mileage').val(response.Mileage).change(); I can see the "Mileage" field updated with the correct number, but when I hit OK on the partial view to post the form back to the controller, the "Mileage" property of the model being returned to the controller is null. The only property values that are sent back to the controller are those that the user filled in prior to making the ajax call for the "Mileage" number. Is there a different way I should be setting the model property?
asked at 29 Jun 2022
I found the problem. I wanted the mileage number to not be editible by the end user, so I placed it's EditorFor inside a div. I then disabled the editor like this: $('#mileage_div:input').attr("disabled", true); So, I was able to have ajax update the value of the field, but this line prevented the data from being sent back to the controller when the form was posted. What's the best way to disable entry on that div but still have the data flow back to the controller?
at 29 Jun 2022
to leave an answer
By accessing this site, you agree to store cookies on your device and disclose information in accordance with our