gpt4 book ai didi

asp.net-mvc-2 - 渲染与父 View 同名的部分 - WebDev.WebServer40.exe 崩溃

转载 作者:行者123 更新时间:2023-12-02 13:38:12 24 4
gpt4 key购买 nike

我想知道是否其他人也有同样的问题,还是只有我一个人遇到同样的问题!

假设我有一个 View Purchases.aspx 和一个部分 View 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 可以解决此问题。请注意,您需要在 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",
};
}
}

关于asp.net-mvc-2 - 渲染与父 View 同名的部分 - WebDev.WebServer40.exe 崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3363847/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com