代码之家  ›  专栏  ›  技术社区  ›  Jamie Dixon

呈现与父视图同名的部分-崩溃WebDev.WebServer40.exe

  •  2
  • Jamie Dixon  · 技术社区  · 14 年前

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

    Purchases.aspx 以及局部视图 Purchases.ascx

    采购.aspx 如果我这样做了: Html.RenderPartial("Purchases") 然后WebDev.WebServer40.exe基本上关闭。

    我猜这是由堆栈溢出引起的,因为 RenderPartial

    这是一个错误,这是一个明确的行为,还是只是发生在我身上?

    1 回复  |  直到 14 年前
        1
  •  7
  •   Ahmad    14 年前

    它是一种定义行为,因为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",
                        };
        }
    }