Render Partial with the same name as the parent View - WebDev.WebServer40.exe failed

I am wondering if other people have the same problem or is it just me!

Given that I have View Purchases.aspx and a partial view of Purchases.ascx :

Inside Purchases.aspx , if I do: Html.RenderPartial("Purchases") , then WebDev.WebServer40.exe basically closes.

I assume this is caused by a stack overflow because RenderPartial cannot determine what it should display (.aspx or .ascx).

Is this a mistake, is this a specific behavior, or is it just happening to me?

+2
source share
1 answer

The behavior is determined, since ViewLocationFormats and PartialViewLocationFormats are defined as follows, and the aspx page will be considered first.

 ViewLocationFormats = new[] { "~/Views/{1}/{0}.aspx", "~/Views/{1}/{0}.ascx", "~/Views/Shared/{0}.aspx", "~/Views/Shared/{0}.ascx" }; PartialViewLocationFormats = ViewLocationFormats; 

PartialViewLocationFormats should exclude aspx definitions in my opinion. Overriding the default WebFormViewengine may solve this problem. Note: you 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", }; } } 
+7
source

Source: https://habr.com/ru/post/899020/


All Articles