使用HTML,而不是CSHTML [英] Using Html instead of csHtml

查看:3264
本文介绍了使用HTML,而不是CSHTML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用纯HTML页面,而不是用CSHTML MVC .NET。
但是,当我通过右键单击添加索引视图我可以看到只有两个选项。

 公共类HomeController的:控制器
{
    //
    // 回家/    公众的ActionResult指数()
    {
        返回查看();
    }}


  1. CSHTML(剃刀)

  2. .aspx的

我跟着
<一href=\"http://stackoverflow.com/questions/5110970/can-i-serve-html-files-using-razor-as-if-they-were-cshtml-files-without-changi\">Can我所服务使用剃须刀,好像他们是.cshtml文件,.html文件,而不改变我的所有页面的扩展?

论坛,但仍然没有帮助。我还没有看到一个选项,添加HTML而不是CSHTML

我也试过直接添加HTML页面来查看文件夹,但我不知道怎么点从我的控制器功能这一观点。

将以index.html更换Index.cshtml给了我这个错误

 视图索引或它的主人没有被发现或没有视图引擎支持搜索位置。在以下地点被搜查:〜/查看/主页/的Index.aspx
〜/查看/主页/ Index.ascx
〜/查看/共享/的Index.aspx
〜/查看/共享/ Index.ascx
〜/查看/主页/ Index.cshtml
〜/查看/主页/ Index.vbhtml
〜/查看/共享/ Index.cshtml
〜/查看/共享/ Index.vbhtml


解决方案

您可以创建一个普通CSHTML文件查看其添加到控制器和视图本身只使用纯HTML,并添加以下顶端:

  @ {
    布局= NULL;
}

您使用不使用你掌握排版文件CSHTML文件这种方式。而就提供你把任何HTML在里面。

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();
    }}

  1. Cshtml (Razor)
  2. Aspx

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

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

解决方案

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.

这篇关于使用HTML,而不是CSHTML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆