C # MVC FindPartialView cannot find path

I am using MVC4. I am trying to get an html string representation.

ViewEngineResult viewResult = ViewEngines.Engines.FindPartialView(ControllerContext, viewName); 

I put the viewname as "create". But returning to viewResult is a null representation and shows SearchedLocartion as well

 ~/Views/LWWApplication/Create.aspx ~/Views/LWWApplication/Create.ascx ~/Views/Shared/Create.aspx ~/Views/LWWApplication/Create.cshtml ~/Views/Shared/Create.cshtml 

Actually the fourth one file (~ / Views / LWWApplication / Create.cshtml) .but returned as not found.View and the controller contains the same folder structure.

Please, help.

+4
source share
2 answers

Try this, it works in MVC3

ViewName must contain the whole path, for example ~/Views/Shared/_Create.cshtml

  ViewEngineResult viewResult = ViewEngines.Engines.FindPartialView(ControllerContext, viewName); 
+16
source

Specify the full location of the partial display:

 var viewResult = ViewEngines.Engines.FindPartialView(ControllerContext, "~/Areas/AreaName/Views/Preferences/Email.cshtml"); 
+5
source

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


All Articles