views:

815

answers:

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 
});
+2  A: 

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
+1  A: 

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
A: 

Many thanks Kieron and Dan.

Ben Aston