tags:

views:

88

answers:

3

Hi,

Do I have to manually pass my strongly typed viewdata to the call return View(); ?

ie.

MyViewData vd = new MyViewData();

vd.Blah = "asdf asdfsd";

return View();

It seems if I pass it as a parameter, I have to repeat the view name also?

return View("index", vd);
A: 

Normally you don't have to manually pass it, but your model has to have a constructor without parameters. Otherwise the framework won't know what values you would like it to pass there.

As for passing the view name, just check out all method overloads. If there is one with just the model as a parameter, then you can omit the view name.

User
A: 

You can do this:

public ActionResult Action()
{
    var vd = new MyViewData();

    vd.Blah = "asdf asdfsd";

    ViewData.Model = vd;

    return View();
}
Garry Shutler
+1  A: 

you can simply pass the model the the View method:

MyViewData vd = new MyViewData();

vd.Blah = "asdf asdfsd";

return View(vd);
Marwan Aouida