use*_*017 17 asp.net asp.net-mvc razor
我想使用纯HTML页面而不是使用MVC .net的cshtml.但是当我通过右键单击索引添加视图时,我只能看到两个选项.
public class HomeController : Controller
{
//
// GET: /Home/
public ActionResult Index()
{
return View();
}}
Run Code Online (Sandbox Code Playgroud)
我跟着 我可以使用Razor提供.html文件,好像它们是.cshtml文件而不改变我所有页面的扩展名吗?
论坛但仍无济于事.我仍然没有看到添加html而不是cshtml的选项
我也尝试直接添加html页面到视图文件夹,但我不知道如何从我的控制器功能指向该视图.
用Index.html替换Index.cshtml给了我这个错误
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
Run Code Online (Sandbox Code Playgroud)
ser*_*adh 11
您可以创建一个带有常规cshtml文件的视图,将其添加到控制器,在View本身中只需使用纯HTML并将以下内容添加到顶部:
@{
Layout = null;
}
Run Code Online (Sandbox Code Playgroud)
这样您就可以使用不使用主布局文件的cshtml文件.并且只是提供你放入它的任何HTML.
abd*_*sit 11
为了呈现纯HTML文件,您可以使用
return new FilePathResult(HtmlPath, "text/html");
Run Code Online (Sandbox Code Playgroud)
HtmlPath所在的位置
Server.MapPath(string.Format("~/Views/{0}/{1}.html", YourControllerName, YourHtmlfileName))
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
15347 次 |
最近记录: |