Register generic page base class

放肆的年华 提交于 2019-12-07 01:04:41

问题


I create my own generic page base class:

public abstract class ViewPageBase<TModel> : WebViewPage<TModel>
{
    public ParamBuilder<TModel> Param { get { return new ParamBuilder<TModel>(Model); } }
}

Web.config:

<system.web.webPages.razor>
  <host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
  <pages pageBaseType="ViewPageBase">
    <namespaces>
      <add namespace="System.Web.Mvc" />
      <add namespace="System.Web.Mvc.Ajax" />
      <add namespace="System.Web.Mvc.Html" />
      <add namespace="System.Web.Routing" />
    </namespaces>
  </pages>
</system.web.webPages.razor>

This entry causes the following errors:

INCORRECT_TYPE_PARAMETER_NUMBER

And

An expression tree may not contain a dynamic operation

How do I register a generic page base class with ASP.NET MVC4 without using the @inherits keyword in each Razor view?


回答1:


This should work. The error you are getting is not related to the custom view page.



来源:https://stackoverflow.com/questions/11711959/register-generic-page-base-class

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!