Obviously real life applications are a lot more complex but for this example sake lets say I have the following simple view and I need to save the User:
@model UserViewModel
@Html.TextBoxFor(model=>model.FirstName)
</br>
@Html.TextBoxFor(model=>model.MiddleName)
</br>
@Html.TextBoxFor(model=>model.LastName)
When submitted there are two ways how I can receive it at the Controller level:
1)
public ActionResult(UserViewModel user)
{
var myUser = new User();
myUser = user.FirstName;
myUser = user.MiddleName;
myUser = user.LastName;
}
and
2)
public ActionResult(FormCollection collection)
{
var myUser = new User();
myUser = collection.Get("FirstName");
myUser = collection.Get("MiddleName");
myUser = collection.Get("LastName");
}
Question: Is there a reason to use one method over another ? Also a few developers told me that second method is preferred. That passing object the whole object like shown in the first example is not a good idea. Why ?