Asp.net mvc 如何在ASP.NET MVC2中将强类型视图WebForms.aspx模板放置在非标准位置?
所以,我个人认为这是一种打击 我将.aspx模板放在非标准位置。在本例中,它的虚拟路径为Asp.net mvc 如何在ASP.NET MVC2中将强类型视图WebForms.aspx模板放置在非标准位置?,asp.net-mvc,asp.net-mvc-2,asp.net-mvc-views,asp.net-mvc-templates,Asp.net Mvc,Asp.net Mvc 2,Asp.net Mvc Views,Asp.net Mvc Templates,所以,我个人认为这是一种打击 我将.aspx模板放在非标准位置。在本例中,它的虚拟路径为~/Content/Sites/magical/Index.aspx 然后,我创建了自己的视图引擎作为测试,它扩展了WebFormsViewEngine: public class MagicalWebFormsViewEngine : WebFormViewEngine { public override ViewEngineResult FindView(ControllerContext co
~/Content/Sites/magical/Index.aspx
然后,我创建了自己的视图引擎作为测试,它扩展了WebFormsViewEngine:
public class MagicalWebFormsViewEngine : WebFormViewEngine
{
public override ViewEngineResult FindView(ControllerContext controllerContext, string viewName, string masterName, bool useCache)
{
string viewTemplatePath = "~/Content/Sites/magical/" + viewName + ".aspx";
string masterTemplatePath = string.Empty;
return new ViewEngineResult(
this.CreateView(controllerContext, viewTemplatePath, masterTemplatePath),
this
);
}
}
模板如下所示:
<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Plain.Master" Inherits="System.Web.Mvc.ViewPage<MySoln.Client.Presentation.MyPresenter>" %>
...
<%: Model.SomePresenterSpecificMember %>
所以,我的问题是,为什么前者和后者都起作用?我不希望在每个模板顶部的标记中将模型强制转换为我的演示者类型之一
谢谢 只需确保在自定义视图引擎路径的根目录下有以下web.config文件:
<?xml version="1.0"?>
<configuration>
<system.web>
<httpHandlers>
<add path="*" verb="*" type="System.Web.HttpNotFoundHandler"/>
</httpHandlers>
<!--
Enabling request validation in view pages would cause validation to occur
after the input has already been processed by the controller. By default
MVC performs request validation before a controller processes the input.
To change this behavior apply the ValidateInputAttribute to a
controller or action.
-->
<pages
validateRequest="false"
pageParserFilterType="System.Web.Mvc.ViewTypeParserFilter, System.Web.Mvc, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"
pageBaseType="System.Web.Mvc.ViewPage, System.Web.Mvc, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"
userControlBaseType="System.Web.Mvc.ViewUserControl, System.Web.Mvc, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
<controls>
<add assembly="System.Web.Mvc, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" namespace="System.Web.Mvc" tagPrefix="mvc" />
</controls>
</pages>
</system.web>
<system.webServer>
<validation validateIntegratedModeConfiguration="false" />
<handlers>
<remove name="BlockViewHandler"/>
<add name="BlockViewHandler" path="*" verb="*" preCondition="integratedMode" type="System.Web.HttpNotFoundHandler" />
</handlers>
</system.webServer>
</configuration>
您可以将默认模板自动生成并位于~/views/web.config
中的web.config文件复制粘贴到~/content/web.config
中
基本上,重要的部分是:
pageBaseType=“System.Web.Mvc.ViewPage,System.Web.Mvc,…”
只需确保在自定义视图引擎路径的根目录下有以下Web.config文件:
<?xml version="1.0"?>
<configuration>
<system.web>
<httpHandlers>
<add path="*" verb="*" type="System.Web.HttpNotFoundHandler"/>
</httpHandlers>
<!--
Enabling request validation in view pages would cause validation to occur
after the input has already been processed by the controller. By default
MVC performs request validation before a controller processes the input.
To change this behavior apply the ValidateInputAttribute to a
controller or action.
-->
<pages
validateRequest="false"
pageParserFilterType="System.Web.Mvc.ViewTypeParserFilter, System.Web.Mvc, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"
pageBaseType="System.Web.Mvc.ViewPage, System.Web.Mvc, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"
userControlBaseType="System.Web.Mvc.ViewUserControl, System.Web.Mvc, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
<controls>
<add assembly="System.Web.Mvc, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" namespace="System.Web.Mvc" tagPrefix="mvc" />
</controls>
</pages>
</system.web>
<system.webServer>
<validation validateIntegratedModeConfiguration="false" />
<handlers>
<remove name="BlockViewHandler"/>
<add name="BlockViewHandler" path="*" verb="*" preCondition="integratedMode" type="System.Web.HttpNotFoundHandler" />
</handlers>
</system.webServer>
</configuration>
您可以将默认模板自动生成并位于~/views/web.config
中的web.config文件复制粘贴到~/content/web.config
中
基本上,重要的部分是:
pageBaseType=“System.Web.Mvc.ViewPage,System.Web.Mvc,…”
我要仔细检查一下,这看起来像是标准错误,其中“MySoln.Client.Presentation.MyPresenter”不正确。另外,当您执行后面的操作时,是否运行它以确保它在运行时不会失败?我在inherits中仔细检查了声明,仍然存在相同的问题。是的,我实际上已经运行了后者以确保正确渲染。谢谢你的建议!我会反复检查,这看起来像是标准错误,其中“MySoln.Client.Presentation.MyPresenter”不正确。另外,当您执行后面的操作时,是否运行它以确保它在运行时不会失败?我在inherits中仔细检查了声明,仍然存在相同的问题。是的,我实际上已经运行了后者以确保正确渲染。谢谢你的建议!那么,这是否意味着任何包含模板的虚拟目录树的根文件夹中都必须有这个kludgy web.config?出于好奇,这种行为有没有记录在案?我想读一下背后的原因等等。再次感谢@Michael,重要的是pageBaseType
属性指示基本类型的ASP.NET编译器。那么,这是否意味着任何包含模板的虚拟目录树的根文件夹中都必须包含此kludgy web.config?出于好奇,这种行为有没有记录在案?我想读一下背后的原因等等。再次感谢@Michael,重要的是pageBaseType
属性指示基本类型的ASP.NET编译器。