I have an ASP.NET MVC project and I want to put CSHTML files outside of Views Folder. While I can do so easily by adding the CSHTML files in my desired folder, I am not able to render partial view result from these files.
The folder structure I currently have is roughly as follows: Root | |--Templates | |---Welcome.cshtml | |--Views | |---
I'm using the below syntax from one of the controller actions
public ActionResult Welcome()
{
return PartialView("Welcome");
}
However, doing so, razor is not able to locate the Welcome.cshtml. I have read about using a custom view engine to change the default search location etc. etc. but wondering if this just can be solved by addition configuration.
You can specify the root-relative path when returning a View/PartialView. For example:
public PartialViewResult Welcome()
{
return PartialView("~/Templates/Welcome.cshtml");
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With