Render Partial of same name as parent View - Crashes WebDev.WebServer40.exe

后端 未结 1 963
醉梦人生
醉梦人生 2021-01-07 01:08

I\'m wondering whether other people are having this same issue or whether it\'s just me !

Given I have a View Purchases.aspx and a partial view Pu

相关标签:
1条回答
  • 2021-01-07 01:46

    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 should exclude the aspx definitions in my opinion. Overriding the default WebFormViewengine can resolve this. Note, you will need to register this in the Application_Start() method

    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",
                        };
        }
    }
    
    0 讨论(0)
提交回复
热议问题