我想知道需要将哪些文件添加到空白的 .NET c# Razor 项目中才能加载我的第一页。
我创建了一个名为 Index.cshtml 的视图,其中包含:
@{
ViewBag.Title = "Index";
}
<h2>@ViewBag.Title</h2>
我创建了一个名为 HomeController.cs 的控制器:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace My_Website.Models
{
public class HomeController : Controller
{
//
// GET: /Default1/
public ActionResult Index()
{
return View();
}
}
}
当我运行此应用程序时,我收到以下错误:
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
有没有办法将脚本重定向到直接在 View 文件夹中指向 Index.cshtml 而不必放入主目录以满足默认布局?