tags:

views:

26

answers:

2

I'm kind of a noob so please forgive me if this is a dumb question.

I am loading a page successfully using Model Binding in ASP.NET MVC 2. Now I want to use Model Binding to submit the results of a form, but I want to use a different Model that the one I loaded with. Is this possible? Or should I just use the same ViewModel for both purposes?

+1  A: 

Yes it's definitely possible.

The only thing to remember is the name attributes on your form inputs must be the same as the properties in the viewmodel.

Currently I have a hand crafted form (no strongly typed helpers) which once posted binds to a view model.

Alastair Pitts
So I can't use the strongly typed helpers? Sorry, I'm confused.
Mike C.
Alastair Pitts
A: 

Yes, that is possible. Your details controller action and create controller action are different methods so you can make them accept whatever types you want.

    //
    // GET /Test/12
    public ActionResult Details(int id)
    {
        return View(new ViewModel{/*properties init*/});
    }

    //
    // POST: /Test/Update
    [HttpPost]
    public ActionResult Update(UpdateModel model)
    {
        //Do something with the model
        return RedirectToAction("Index");
    } 
Igor Zevaka
I'm more interested in an example of the View using Model Binding. The part you posted makes sense to me.
Mike C.