Html helper does not use custom VirtualPathProvider

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. :(

+7
c # razor asp.net-mvc-4
source share
1 answer

LostInComputer user was kind enough to pass on a sample project that worked on my laptop, and I was confused by what would be the difference.

Usually one would expect that the Html helpers would work only for VirtualPathProvider , and now I know what it should be.

The real problem is installing a specific computer on which I encountered a problem, and after reinstalling everything works fine. So this is not a very difficult decision, but since there was little attention to this question, I at least give him my own answer, because someday it can be useful to someone else, how boring it is. :)

When you probably expect something to work, you can always try to run it on another machine (if you have one available, of course), because in the end, everything that may be wrong can just be a damaged installation. : (

+4
source share

All Articles