It would be very help to create public property to expose PrecompiledMvcView _virtualPath with a private set.
We have a custom ViewStartPageExtensions class that provides an extension point for custom layout implementations. The current implementation casts the IView to BuildManagerCompiledView and checks the ViewPath. Unfortunately, casting the IView to PrecompiledMvcView does not provide access to _virtualPath with the needed information.
_ViewStart.cshtml example:
@{
Layout = this.GetLayout("_SiteLayout");
}
Extension:
public static string GetLayout(this ViewStartPage viewStartPage, string layoutName)
{
if (viewStartPage.Context.Request.IsAjaxRequest())
{
return null;
}
if (layoutName.StartsWith("~"))
return layoutName;
return GetViewVirtualPath(viewStartPage.ViewContext, layoutName);
}
private static string GetViewVirtualPath(ViewContext viewContext, string layoutName)
{
var viewResult = ViewEngines.Engines.FindView(viewContext.Controller.ControllerContext, layoutName, string.Empty);
if (viewResult != null)
{
var view = viewResult.View as BuildManagerCompiledView;
if (view != null)
return view.ViewPath;
var precompiledView = viewResult.View as PrecompiledMvcView;
// Proposed public property to expose value of _virtualPath
if (precompiledView != null)
return precompiledView.VirtualPath;
}
return null;
}
Is there a reason the _virtualPath is private? The value is already annotated in the generated.cs PageVirtualPathAttribute but I want to avoid having to write a custom provider to cache this information separately for lookups. Getting the value directly from the ViewEngines would be preferable.
Thanks.
Comments: Fixed in changeset 54402c127ed1
We have a custom ViewStartPageExtensions class that provides an extension point for custom layout implementations. The current implementation casts the IView to BuildManagerCompiledView and checks the ViewPath. Unfortunately, casting the IView to PrecompiledMvcView does not provide access to _virtualPath with the needed information.
_ViewStart.cshtml example:
@{
Layout = this.GetLayout("_SiteLayout");
}
Extension:
public static string GetLayout(this ViewStartPage viewStartPage, string layoutName)
{
if (viewStartPage.Context.Request.IsAjaxRequest())
{
return null;
}
if (layoutName.StartsWith("~"))
return layoutName;
return GetViewVirtualPath(viewStartPage.ViewContext, layoutName);
}
private static string GetViewVirtualPath(ViewContext viewContext, string layoutName)
{
var viewResult = ViewEngines.Engines.FindView(viewContext.Controller.ControllerContext, layoutName, string.Empty);
if (viewResult != null)
{
var view = viewResult.View as BuildManagerCompiledView;
if (view != null)
return view.ViewPath;
var precompiledView = viewResult.View as PrecompiledMvcView;
// Proposed public property to expose value of _virtualPath
if (precompiledView != null)
return precompiledView.VirtualPath;
}
return null;
}
Is there a reason the _virtualPath is private? The value is already annotated in the generated.cs PageVirtualPathAttribute but I want to avoid having to write a custom provider to cache this information separately for lookups. Getting the value directly from the ViewEngines would be preferable.
Thanks.
Comments: Fixed in changeset 54402c127ed1