How to serve html file from another directory as ActionResult

Aran Mulholland picture Aran Mulholland · May 31, 2012 · Viewed 45.3k times · Source

I have a specialised case where I wish to serve a straight html file from a Controller Action.

I want to serve it from a different folder other than the Views folder. The file is located in

Solution\Html\index.htm

And I want to serve it from a standard controller action. Could i use return File? And how do I do this?

Answer

Wahid Bitar picture Wahid Bitar · May 31, 2012

Check this out :

    public ActionResult Index()
    {
        return new FilePathResult("~/Html/index.htm", "text/html");
    }