RazorViewEngine doesn't find view when basePath is attached

Hi I have a project where i use the RazorViewEngine to generate pdf-files.

However I have some problem locating the razorviews. The ViewEngine does find the razor views if I do not include the full path like this C:/.../../Views/pdfitem.cshtml, but does find them if i only provide /Views/pdfitem.cshtml. Why is this? I need to be able to provide the full path.

Thanks!

1 answer

  • answered 2021-05-15 00:54 Transformer

    Can you post the error you are getting,

    Guessing it could be couple things, cache? or how its appending the path? or even if you are behind a reverseProxy?

    • Solving you cache issue from user crichavin

      //to avoid used Cached paths. see one of the comments here: http://lonetechie.com/2012/09/25/multi-tenant-architecture-with-asp-net-mvc-4/
          public override ViewEngineResult FindView(ControllerContext controllerContext, string viewName, string masterName, bool useCache)
          {
              return base.FindView(controllerContext, viewName, masterName, false);
          }
      
          //to not used Cached paths. see one of the comments here: http://lonetechie.com/2012/09/25/multi-tenant-architecture-with-asp-net-mvc-4/
          public override ViewEngineResult FindPartialView(ControllerContext controllerContext, string partialViewName, bool useCache)
          {
              return base.FindPartialView(controllerContext, partialViewName, false);
          }
      

    • Try using both GetView(...) and FindView(...) to troubleshoot. GetView(...) handles paths relative to the current location while FindView(...) searches in the view locations.

      var viewEngineResult = _viewEngine.GetView(ViewContext.ExecutingFilePath, partialName, isMainPage: false);
      var getViewLocations = viewEngineResult.SearchedLocations;
      if (!viewEngineResult.Success)
      {
         viewEngineResult = _viewEngine.FindView(ViewContext, partialName, isMainPage: false);
      }