Let’s say I have a setup like this:
public ActionResult Create(int someUnrelatedNumber)
{
...
return View();
}
[Post]
public ActionResult Create(SomeModel model, int someUnrelatedNumber)
{
...
}
Is there a way to pass ‘someUnrelatedNumber’ between them without creating a view model that contains ‘SomeModel’ and ‘someUnrelatedNumber’?
You could use the ViewBag (or possibly even TempData if I understand what you’re trying to do), but I tend to lean towards strongly typed view models whenever possible.
http://rachelappel.com/when-to-use-viewbag-viewdata-or-tempdata-in-asp.net-mvc-3-applications
On the model binder side it will typically handle the bindings correctly, but you may have to provide hints to get it binding both SomeModel and a separate someUnrelatedNumber. Something like the following in the view.
etc…