I have some very basic code to simulate a form post into a controller that updates the model. In this case, say the "ActiveYesNo" was accidentially entered (Should be "ActiveYn" to match what's in the form).
SaveChanges runs ok but nothing is updated as expected. But I guess I thought there would be some type of binding error since there is no property called "ActiveYesNo" in the user object.
User user = new User()
var fakeForm = new FormCollection();
fakeForm.Add("ActiveYn", "true");
if (TryUpdateModel(user, new[] { "ActiveYesNo"}, fakeForm.ToValueProvider()))
{
db.SaveChanges();
}
else
{
throw new System.Exception("operation was invalid.");
}
Dave5574
Member
30 Points
62 Posts
Trying to understand TryUpdateModel
Mar 27, 2012 08:23 PM|LINK
Hi,
I have some very basic code to simulate a form post into a controller that updates the model. In this case, say the "ActiveYesNo" was accidentially entered (Should be "ActiveYn" to match what's in the form).
SaveChanges runs ok but nothing is updated as expected. But I guess I thought there would be some type of binding error since there is no property called "ActiveYesNo" in the user object.
User user = new User()
var fakeForm = new FormCollection();
fakeForm.Add("ActiveYn", "true");
if (TryUpdateModel(user, new[] { "ActiveYesNo"}, fakeForm.ToValueProvider()))
{
db.SaveChanges();
}
else
{
throw new System.Exception("operation was invalid.");
}