I want to use pure html page instead of cshtml with MVC .net. But when I add view by right clicking Index i can see only two options.
public class HomeController : Controller
{
//
// GET: /Home/
public ActionResult Index()
{
return View();
}}
- Cshtml (Razor)
- Aspx
forum but still no help. I still don’t see an option to add html instead of cshtml
I also tried adding html page directly to view folder but i dont know how to point that view from my controller function.
Replacing Index.cshtml with Index.html gave me this error
The view 'Index' or its master was not found or no view engine supports the searched locations. The following locations were searched:
~/Views/Home/Index.aspx
~/Views/Home/Index.ascx
~/Views/Shared/Index.aspx
~/Views/Shared/Index.ascx
~/Views/Home/Index.cshtml
~/Views/Home/Index.vbhtml
~/Views/Shared/Index.cshtml
~/Views/Shared/Index.vbhtml
In order to render plain HTML file you can use
where HtmlPath is
If you right click on your
Content
folder you can select 'Add new item...'. You can then select 'Web' in the tree on the left and choose the 'HTML Page' on the right.This should add you an HTML page.
Add a file. Rename it. F2 in solution explorer.
You can create a View with a regular cshtml file add it to the controller and in the View itself just use pure html and add the following to the top:
This way you use a cshtml file that doesn't use you master layout file. And just serves whatever html you put in it.
If it's a static html file you don't need to point your controller to it, because IIS can serve them just fine. Add an html file to your project (anywhere but NOT in the viewsfolder), and point your browser to that file.