My view won´t derive from ViewPage<MyViewModel>

I’m a total newbie with ASP NET MVC

I’m trying to make the view Index.aspx inherit from ViewPage<FeaturedProductsViewModel> by declaring it as:

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

But I get this error message:

The view at '~/Views/Home/Index.aspx' must derive from ViewPage, ViewPage<TModel>, ViewUserControl, or ViewUserControl<TModel>

FeaturedProductsViewModel (which I expect to be the TModel for this view) is declared in the Models folder:

The view Index.aspx starts with:

<%@ Import Namespace="Ploeh.Samples.Commerce.Web.Models" %>
<%@ Page Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<FeaturedProductsViewModel>" %>

FeaturedProductsViewModel is located in the Ploeh.Samples.Commerce.Web.Models namespace.

Thanks in advance

Rafael

1. what version of MVC?

2. MVC have not masterpage, but layout

I have MVC 4, but when I had version 3, it also happened.

Right click on the actionmethod name, then select create view, in the next page select Strongly Typed View and find the View Model.  That’s all there is to it.

Leave a Reply