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

7
  • 1
    Can one of these help? For asp.net core stackoverflow.com/a/43473813/8715436 and for asp.net mvc based on .net framework something like this stackoverflow.com/a/7003742/8715436 Commented Feb 25, 2022 at 23:14
  • What is the error message you're receiving? Commented Feb 25, 2022 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 Commented Feb 25, 2022 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. Commented Feb 25, 2022 at 23:54
  • 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. Commented Feb 26, 2022 at 0:14

1 Answer 1

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
Sign up to request clarification or add additional context in comments.

1 Comment

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.