views:

47

answers:

1

I create a class to hold view data for two different types from my model.

class FooBarViewData
{
    public List<Foo> Foos { get; set; }
    public List<Bar> Bars { get; set; }
}

I typed my view to a FooBarViewData but it fails to find the type.

<%@ Page Title="" 
    Language="C#" 
    MasterPageFile="~/Views/Shared/Site.Master" 
    Inherits="System.Web.Mvc.ViewPage<FooBarViewData>" %>

How can I get this to work. Also once it does work, how do I access Foo and Bar, by a key on the ViewData collection or another way?

+1  A: 

Did you try specifying the full namespace? Like, err, MyProject.ViewDTO.FooBarViewData ?

When it DOES register, you can access your typed viewdata via the Model property on the view. This should work:

<% foreach(Foo foo in Model.Foos) { %>
  <%= Foo.ToString() %>
<% } %>
Erik van Brakel