I’m working on a MVC3 web-application and encounter a problem when passing values from my model back to a Action using AJAX.
When I
1) browse to this view
2) alter the Quantity textbox
3) hit save
I get the same value for “Quantity” as I get when I pass the Model into the View. I would expect the Model to be synchronous with the Textfields but apperently they are not. I need either the Model to be synchronized – or some other way of getting the new “Quantity” value into the ActionLink.
— SOLUTION :
Basically the reason why my FormCollection did not update was because I was using the Html.BeginForm function, and calling Ajax.ActionLink. These do not work well together. When changing to Ajax.BeginForm I successfully was able to return the updated FormCollection.
(I cannot paste code here now because it’s been refactored alot and is not recognizable)
To update a model you will need to issue a POST. Then you will need to adorn your Save method with the HttpPost attribute and accept your model as the first argument. The framework will pass the argument to you.
Here is a supporting article on this forum.
ASP.NET MVC [HttpPost] action accepts single object, spits back validation errors to ViewPage<CustomViewModel>
EDIT
Added a modified link more directly related to Ajax ActionLink — MVC Ajax.ActionLink doesn't find POST method