Using Html instead of csHtml

前端 未结 5 2117
我寻月下人不归
我寻月下人不归 2020-12-16 12:46

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 HomeContr         


        
相关标签:
5条回答
  • 2020-12-16 13:25

    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.

    0 讨论(0)
  • 2020-12-16 13:31

    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:

    @{
        Layout = null;
    }
    

    This way you use a cshtml file that doesn't use you master layout file. And just serves whatever html you put in it.

    0 讨论(0)
  • 2020-12-16 13:31

    In order to render plain HTML file you can use

    return new FilePathResult(HtmlPath, "text/html");
    

    where HtmlPath is

    Server.MapPath(string.Format("~/Views/{0}/{1}.html", YourControllerName, YourHtmlfileName))
    
    0 讨论(0)
  • 2020-12-16 13:39

    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.

    0 讨论(0)
  • 2020-12-16 13:44

    Add a file. Rename it. F2 in solution explorer.

    0 讨论(0)
提交回复
热议问题