Asp.net mvc 2 呈现与父视图同名的部分-崩溃WebDev.WebServer40.exe
我想知道是其他人也有同样的问题,还是只有我一个人 假设我有一个视图Asp.net mvc 2 呈现与父视图同名的部分-崩溃WebDev.WebServer40.exe,asp.net-mvc-2,Asp.net Mvc 2,我想知道是其他人也有同样的问题,还是只有我一个人 假设我有一个视图Purchases.aspx和一个部分视图Purchases.ascx: 在Purchases.aspx中如果我这样做:Html.RenderPartial(“Purchases”)则WebDev.WebServer40.exe基本上关闭 我猜这是由堆栈溢出引起的,因为RenderPartial无法确定它应该渲染什么(.aspx或.ascx) 这是一个错误,是一个已定义的行为,还是仅仅发生在我身上?这是已定义的行为,因为ViewL
Purchases.aspx
和一个部分视图Purchases.ascx
:
在Purchases.aspx中
如果我这样做:Html.RenderPartial(“Purchases”)
则WebDev.WebServer40.exe基本上关闭
我猜这是由堆栈溢出引起的,因为RenderPartial
无法确定它应该渲染什么(.aspx或.ascx)
这是一个错误,是一个已定义的行为,还是仅仅发生在我身上?这是已定义的行为,因为ViewLocationFormats和PartialViewLocationFormats的定义如下,并且将首先查看aspx页面
ViewLocationFormats = new[] {
"~/Views/{1}/{0}.aspx",
"~/Views/{1}/{0}.ascx",
"~/Views/Shared/{0}.aspx",
"~/Views/Shared/{0}.ascx"
};
PartialViewLocationFormats = ViewLocationFormats;
我认为PartialViewLocationFormats应该排除aspx定义。覆盖默认WebFormViewengine可以解决此问题。注意,您需要在应用程序\u Start()
方法中注册它
public class ASPXViewEngine: WebFormViewEngine
{
public ASPXViewEngine()
{
base.PartialViewLocationFormats =
new string[]
{
"~/Views/{1}/{0}.ascx",
"~/Views/Shared/{0}.ascx"
};
base.AreaPartialViewLocationFormats =
new string[]
{
"~/Areas/{2}/Views/{1}/{0}.ascx",
"~/Areas/{2}/Views/Shared/{0}.ascx",
};
}
}