I installed VirtualPathProvider and it works great for direct URLs like http://.../home/index in the address bar.
public class HomeController { public ActionResult Index() { // This triggers MyVirtualPathProvider functionallity when called via // the browsers address bar or anchor tag click for that matter. // But it does not trigger MyVirtualPathProvider for 'in-view' calls like // @{ Html.RenderAction("index", "home"); } return View(); } } public class MyVirtualPathProvider : VirtualPathProvider { public override System.Web.Hosting.VirtualFile GetFile(string virtualPath) { // This method gets hit after the Controller call for return View(...); if (MyCondition) return MyVirtualFileHandler.Get(virtualPath); return base.GetFile(virtualPath); } public override bool FileExists(string virtualPath) { // This method gets hit after the Controller call for return View(...); if (MyCondition) return true; return base.FileExists(virtualPath); } }
However, I would like this to work with the Html helper too, but now it is ignoring VirtualPathProvider for calls to the html helper in the view:
@{ Html.RenderAction("index", "home"); }
Is there any way to solve this problem?
In the appendix, I have an override for WebViewPage, so I could override the initialization for helpers, but I have no clue about what and how.
Edit:
I tried this on two computers and, oddly enough, works on another computer. So the question really becomes the following:
Why does VirtualPathProvider work on one computer and not work 50% on another computer? But then this question would become somewhat vague, even speculative. Nevertheless, I am not happy with this, but it seems to me that I will have to reinstall some things. :(
c # razor asp.net-mvc-4
Silvermind
source share