Let's say you've got a Create View and Controller for Model TeddyBear
. Let's pretend TeddyBear
has an optional MommyBear
property (an int
), which is passed in as an id (via query string or just "example.com/Bears/Create/#"
There are two ways I could set the MommyBear
property on the new TeddyBear
:
In the view, with
@{
ViewBag.Title = "Create";
Model.MommyBear = Request["id"];
}
Or in the controller, with:
[HttpPost]
public ActionResult Create(TeddyBear bear, int id)
{
bear.MommyBear = id;
...
Is either method more efficient? Are there any dangers in using either one? Which is the best practice?