Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can you create a custom razor view baseclass which has a model and a presentationmodel

In MVC2 we have a custom base class

public class OurViewPage<TModel,TPresentationModel> : ViewPage<TModel>

so we have in the view a Model property and a PresentationModel property...

Our Aspx file starts with

<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Our.Master"
 Inherits="OurViewPage<IndexModel,IndexPresentationModel>" %>

With the MVC3 Razor view engine, would something equivalent be possible?

  • from which base class should we inherited.
  • how do you specify in the view which classes a view uses (equivalent of the Page directive)?
like image 522
rekna Avatar asked Oct 25 '22 03:10

rekna


1 Answers

Your class should derive from System.Web.Mvc.WebViewPage<TModel>

In your view file you would add the following line to the top:

@inherits OurWebViewPage<IndexModel, IndexPresentationModel>

Note that you should not use the @model syntax if you have a base class with two generic parameters.

like image 112
marcind Avatar answered Oct 30 '22 02:10

marcind