CSHTML file outside the view folder

I have an ASP.NET MVC project and I want to put CSHTML files outside of the Views folder. While I can do this easily by adding the CSHTML files to the correct folder, I cannot display a partial result from those files.

The folder structure I currently have is something like this: root | | --Templates | | --- Welcome.cshtml | | --Views | | ---

I am using the below syntax from one of the controller actions

    public ActionResult Welcome()
    {
        return PartialView("Welcome");
    }

      

However, while doing this, the razor cannot find Welcome.cshtml. I've read about using a custom view engine to change the default search location, etc., but wondering if this can be solved just by adding a config.

+3


source to share


1 answer


You can specify the root path when returning the View / PartialView. For example:



public PartialViewResult Welcome()
{
    return PartialView("~/Templates/Welcome.cshtml");
}

      

+2


source







All Articles