Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

5
  • The real question is: why is the browser making two requests? Do you have some forgotten code somewhere that's invoking the same action, but without sending any data across? Commented Apr 30, 2013 at 17:13
  • Yes I found that fault it was the missing 'Return False' at the end of the function so the page was being posted by AJAX then again via the normal postback. So thats now resolved and i get the data on the first call. However I now find that I can get either the Data bound to my model or the other Form fields that I don't want bound but not both.... Very short hair now with this one... Commented May 2, 2013 at 15:00
  • You have a number of options here, but the simplest may be to include the model data on the form's action URL, and submit the form's data itself via AJAX. (You can declare the form using Ajax.Form() instead of HTML.Form()) Commented May 2, 2013 at 15:59
  • Ok can you explain this a little further please, as I have been playing around and again all I manage to achieve it get the form data or the JSON Model bound but not both. If it makes a difference I actually don't need it to work via AJAX as I want to take the user to another page after the data is saved, just I can't seem to work out how to bind the JSON data from a normal form, I did try putting it in a hidden input but that didn't work either. Commented May 4, 2013 at 19:50
  • If you know the JSON data at the time that you generate the form, you can pass each of those parameters in the URL rather than in JSON. For example: Html.BeginForm("MyAction", "MyController", new{id = 1, date = "28/04/2013", sim = "B787"}) Commented May 5, 2013 at 5:12