加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

asp.net – 使用Html而不是csHtml

发布时间:2020-12-15 23:00:26 所属栏目:asp.Net 来源:网络整理
导读:我想使用纯 HTML页面而不是cshtml与MVC .net. 但是当我通过右键单击索引添加视图时,我只能看到两个选项. public class HomeController : Controller{ // // GET: /Home/ public ActionResult Index() { return View(); }} Cshtml(Razor) Aspx 我跟着 Can I s
我想使用纯 HTML页面而不是cshtml与MVC .net.
但是当我通过右键单击索引添加视图时,我只能看到两个选项.
public class HomeController : Controller
{
    //
    // GET: /Home/

    public ActionResult Index()
    {
        return View();
    }}

> Cshtml(Razor)
> Aspx

我跟着
Can I serve .html files using Razor as if they were .cshtml files without changing the extension of all my pages?

论坛还是没有帮助.我仍然看不到添加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

解决方法

您可以使用常规cshtml文件创建一个视图,将其添加到控制器,并且在View本身中只需使用纯HTML,并将以下内容添加到顶部:
@{
    Layout = null;
}

这样你就可以使用一个不使用你的主页布局文件的cshtml文件.并且只是提供你放入的任何HTML.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读