Sunday, September 02, 2012

The Following Is A Bad Idea

But do you see why?
public ActionResult Update()
{
ViewModelC c = new ViewModelC();
if(TryUpdateModel(c, "A") && TryUpdateModel(c, "B"))
{
// do some kind of update
returnView("Result");
}
// Display errors
returnView("Add", c);
}



If you don't, comment.

Labels:

2 Comments:

Blogger Don said...

Because of TryUpdateModel "A" succeeds and "B" doesn't...

9/02/2012 10:01 PM  
Blogger Ann said...

Close. If TryUpdateModel "A" fails, TryUpdateModel "B" will never even get executed, and your model will be incomplete, which will have Unexpected Consequences when you try to display it again.

9/03/2012 1:05 PM  

Post a Comment

<< Home