3

In previous releases there were 3 ways to pass data from controller to view AFAIK (shown below).

I want to use method (2) with MVC Beta 1, but I can't find the renderView method. So what's the new syntax (if it's still possible)? Thanks in advance.

Ben.

Syntax #1: Old-school dictionary

ViewData["Name"] = "Moo-moo";
ViewData["Age"] = 6;
ViewData["HasFunnyFace"] = true;
RenderView("ShowCat");

Syntax #2: Explicitly-typed ViewData object

RenderView("ShowCat", new ShowCatViewData {
    Name = "Moo-moo",
    Age = 6,
    HasFunnyFace = true
});

Syntax #3: Anonymously-typed object

RenderView("ShowCat", new { 
    Name = "Moo-moo", 
    Age = 6, 
    HasFunnyFace = true 
});
Ben Aston
  • 53,718
  • 65
  • 205
  • 331

2 Answers2

2

In beta 1, use the View method:

return View ("ShowCat", <TYPED_DATA_SET_OR_OTHER_MODEL>);

The View method has replaced the RenderView method.

Kieron
  • 26,748
  • 16
  • 78
  • 122
1

Following from Kieron's comment, in Visual Studio 2008 (maybe 2005/VSE?), when you right click on your controller action, you can choose 'Add View' at the top of the context menu.

This brings up a little dialog box, which will allow you to create a strongly typed view by specifying it.

Dan Atkinson
  • 11,391
  • 14
  • 81
  • 114