0

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 Answer 1

1

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() %>
<% } %>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.