griegs
griegs

Reputation: 22770

Pass Generic Model to View

I have this in my Page setup;

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

And the interface looks like this;

public interface ILocationsFormViewModel<T>
{
    List<TopLocation<T>> Locations { get; set; }
    List<TrendingItem<ITrendItem>> TrendingLocations { get; set; }
}

T is either ITopHotel or ITopShop etc etc with no properties

The problem is I get this error when I goto the View;

CS0305: Using the generic type 'ILocationsFormViewModel' requires '1' type arguments

Does anyone know how I can pass a class that has a Generic type to a view?

Upvotes: 0

Views: 1320

Answers (1)

Martin Booth
Martin Booth

Reputation: 8595

You probably need the generic type parameter in there:

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

Upvotes: 1

Related Questions