Reputation:
When I submit my MVC Page I get an IvalidOperationException from System.Web.Mvc Controller object in the UpdateModel method.
the MSDN documentation states that this method does the following:
Updates the specified model instance using values from the controller's current value provider.
Is the value provider referencing the current Request object?
Or where exactly does it get the values that it is using to update the model?
And what specifically does the UpdateModel method check and what does it 'mean' when it says that
The model of type 'abcXYZ' was not successfully updated
Thanks
Upvotes: 2
Views: 1459
Reputation: 57967
Yes, the default value provider is referencing the current request object (by default, Request.Form.AllKeys.)
UpdateModel attempts to set any properties on your Model that match the Key in that collection.
If it can't because there's either no setter, or no direct cast is possible, you'll receive that error.
Upvotes: 3
Reputation: 22760
I don't know all the answers to your questions but I've had this issue before and I now check that the model I am trying to update has both getters and setters on it. This normally fixes my problems.
I also now use TryUpdateModel so that I can catch exceptions and I implement validation classes to ensure the minimum requirements of the model are being met.
I also use UpdateModel<MyModel>(Model)
I'll also use, on an insert, something like public ActionResult Create(MyModel myModel){}
Like I said, no specific answer to your question but these are the things I do to make it work.
Hope it helps.
Upvotes: 0