In MVC2 I used to create strongly typed views in a way that when I posted, I never used the FormCollection object. My signatures always looked like so:
[AcceptVerbs(HttpVers.Post)]
public Create(Person newPerson)
{
//code to update the person from the post
}
But now I’m seeing this new TryUpdateModel way where I would just write something like:
[AcceptVerbs(HttpVers.Post)]
public Create()
{
Person thePersonToCreate = new Person()
TryUpdateModel(thePersonToCreate)
{
//Code to create the person if model is valid
}
}
So now it seems I have to mock up the HTTPContext in order to test this method. However, it seems like I can still use the former way using strongly typed methods. I realize that the TryUpdateModel method is an improvement for those who would use the FormCollection method of doing things but why bother with TryUpdateModel?
There are instances where this is desirable. A good example is when your model requires a more complex initialization, or factory method to create.
Now one might argue that a custom ModelBinder is a better solution here, but that might be more effort than it is worth if this is a one off situation. Also, hiding this detail in a ModelBinder makes errors more difficult to debug.
There are other situations I’m sure, but this is just a quick example.