渲染部分相同的名称,父视图 - 崩溃WebDev.WebServer40.exe [英] Render Partial of same name as parent View - Crashes WebDev.WebServer40.exe
问题描述
我不知道其他人是否遇到同样的问题,还是这只是我!
I'm wondering whether other people are having this same issue or whether it's just me !
由于我有一个观点 Purchases.aspx
和局部视图 Purchases.ascx
:
Given I have a View Purchases.aspx
and a partial view Purchases.ascx
:
在 Purchases.aspx
如果我这样做: Html.RenderPartial(购买)
然后WebDev.WebServer40。 exe文件基本关闭。
Within Purchases.aspx
if I do: Html.RenderPartial("Purchases")
then WebDev.WebServer40.exe basically closes.
我猜,这是一个堆栈溢出造成的,因为的RenderPartial
不能确定它应该呈现什么(或的.aspx的.ascx)。
I'm guessing that this is caused by a Stack Overflow because RenderPartial
cannot determine what it's supposed to render (.aspx or .ascx).
这是一个bug,它是一个定义的行为,或者它只是发生的事情对我?
Is this a bug, is it a defined behaviour, or is it just happening for me?
推荐答案
这是自定义ViewLocationFormats行为和PartialViewLocationFormats如下所示和ASPX页面将首先被看作定义。
It is defined behaviour since the ViewLocationFormats and PartialViewLocationFormats are defined as follows and an aspx page will be be looked at first.
ViewLocationFormats = new[] {
"~/Views/{1}/{0}.aspx",
"~/Views/{1}/{0}.ascx",
"~/Views/Shared/{0}.aspx",
"~/Views/Shared/{0}.ascx"
};
PartialViewLocationFormats = ViewLocationFormats;
PartialViewLocationFormats应排除在我看来,ASPX定义。覆盖默认WebFormViewengine可以解决这个问题。请注意,您需要在的Application_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",
};
}
}
这篇关于渲染部分相同的名称,父视图 - 崩溃WebDev.WebServer40.exe的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!