tags:

views:

29

answers:

2

I have a strong typed View

<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<MyPortal.Domain.Kite>" %>

In the view I do a foreach on a list that I placed on ViewData that has a different type

<%
foreach(var item in (List<MyPortal.Domain.Brand>)ViewData["BrandsList"]) { }
%>

Do I have to define the full path of the class: MyPortal.Domain.Brand or is there a better way of doing this. Just saying List<Brand> does not work. Is there a way to inherit MyPortal.Domain from the View so that I can reference all classes under the domain without having to specify full path for each of them.

+1  A: 

There is an import for ASPX pages.

<%@ Import Namespace="Something" %>

http://geekswithblogs.net/seanfao/archive/2008/08/21/124619.aspx

Daniel A. White
A: 

If you want a strongly typed view then why are you passing in an other ViewData, that defeats the purpose of having it strongly typed. If this view does need both types then create an object model that contains both types an strongly type to that object.

Then you can enumerate through each like this,

foreach (var item in Model.My1stType)....

and

foreach (var item in Model.My2ndType)....
Tony Borf