Search code examples
c#asp.net-mvcasp.net-mvc-beta1

ASP.NET MVC Beta 1 - Does It Support Strongly Typed View Data?


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 
});

Solution

  • In beta 1, use the View method:

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

    The View method has replaced the RenderView method.