1

I have this method inside my controller that calls this partial view:

return PartialView("_tinzProdListPageTemplate", tblStoreLocation);

That partial view is inside the Shared folder and the above code works fine and loads the view. But now I want to move _tinzProdListPageTemplate to another folder that is inside the Shared folder called Templates so that I can better organize my project.

I tried these but they don't work. It seems that only when calling straight from the default Shared folder, can you load a partial view from the controller. (I even tried adding .cshtml to the end as the extension on the examples above but did not work either)

return PartialView("Templates/_tinzProdListPageTemplate", tblStoreLocation);

return PartialView("Shared/Templates/_tinzProdListPageTemplate", tblStoreLocation);

return PartialView("~/Shared/Templates/_tinzProdListPageTemplate", tblStoreLocation);

So how do I return a PartialView that is not inside the Shared folder. Its inside a folder that is inside the Shared folder?

I am using ASP.NET MVC 5 running on the .NET Framework.

This is the error I get:

The partial view '_tinzProdListPageTemplate' was not found or no view engine supports the searched locations. The following locations were searched:

~/Views/Store/_tinzProdListPageTemplate.aspx
~/Views/Store/_tinzProdListPageTemplate.ascx
~/Views/Shared/_tinzProdListPageTemplate.aspx
~/Views/Shared/_tinzProdListPageTemplate.ascx
~/Views/Store/_tinzProdListPageTemplate.cshtml
~/Views/Store/_tinzProdListPageTemplate.vbhtml
~/Views/Shared/_tinzProdListPageTemplate.cshtml
~/Views/Shared/_tinzProdListPageTemplate.vbhtml

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
CodeQuest
  • 121
  • 1
  • 14
  • 1
    Can one of these help? For asp.net core https://stackoverflow.com/a/43473813/8715436 and for asp.net mvc based on .net framework something like this https://stackoverflow.com/a/7003742/8715436 – E. Shcherbo Feb 25 '22 at 23:14
  • What is the error message you're receiving? – Charles Feb 25 '22 at 23:49
  • @Charles I am receiving this error message: The partial view '_tinzProdListPageTemplate' was not found or no view engine supports the searched locations. The following locations were searched: ~/Views/Store/_tinzProdListPageTemplate.aspx ~/Views/Store/_tinzProdListPageTemplate.ascx ~/Views/Shared/_tinzProdListPageTemplate.aspx ~/Views/Shared/_tinzProdListPageTemplate.ascx ~/Views/Store/_tinzProdListPageTemplate.cshtml ~/Views/Store/_tinzProdListPageTemplate.vbhtml ~/Views/Shared/_tinzProdListPageTemplate.cshtml ~/Views/Shared/_tinzProdListPageTemplate.vbhtml – CodeQuest Feb 25 '22 at 23:53
  • @E.Shcherbo I took a look at the .net framework example but those seem to be showing how to do it from a view. I am adding this code in my controller. – CodeQuest Feb 25 '22 at 23:54
  • I don't this this is specifically for getting them from a view. I would make a try (even your error is saying about view engine) – E. Shcherbo Feb 25 '22 at 23:57
  • As per the error you shared, the viewengine is not able to identify the location in shared folder to look for partial views. The answer shared by E. Shcherbo solves that by adding that folder in the viewengine. You should give it a try – Chetan Feb 26 '22 at 00:10
  • 1
    @E.Shcherbo haha! sorry I had like 10 tabs open on the browser and when I clicked on your link I thought I was looking at the one you sent me I was actually looking at the another tab on my browser. Thank you . Your post did solve my issue. – CodeQuest Feb 26 '22 at 00:14

1 Answers1

2

A complete view name would look like this

"~/Areas/Public/Views/Home/Index.cshtml"

I think you only forgot to add the extension at the end.

Maybe you want a CustomViewEngine like here
Working with subfolders in custom view engine

If you register a custom view engine then you can set all the search locations like

ViewLocation, PartialViewLocation, MasterLocation
Charles
  • 2,721
  • 1
  • 9
  • 15
  • Yeah I tried that but still did not work. In my case I am calling it from inside a controller. In this particular case adding the extension gives me the same error. – CodeQuest Feb 25 '22 at 23:56