Я только что создал пустой проект MVC и добавил мастер-страницу и 1 представление (индекс). Я также создал контроллер (HomeController). Я также щелкнул правой кнопкой мыши представление Index.aspx и установил его как запуск.
Однако при запуске проекта появляется ошибка - «Ошибка сервера в приложении '/'. Ресурс не найден. Запрошенный URL-адрес: /Views/Index.aspx"
HomeКонтроллер
public ActionResult Index()
{
return View();
}
Показатель
<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server">
<h2>Index</h2>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="head" runat="server">
Test
</asp:Content>
Мастер-страница
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<link href="../../Content/Site.css" rel="stylesheet" />
<title>Test</title>
<asp:ContentPlaceHolder ID="head" runat="server">
</asp:ContentPlaceHolder>
</head>
<body>
<form id="form1" runat="server">
<div class="page">
<div id="header">
</div>
<div id="main">
<asp:ContentPlaceHolder ID="MainContent" runat="server" />
<div id="footer">
</div>
</div>
</div>
</form>
</body>
</html>
Глобальный
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
);
}
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
RegisterRoutes(RouteTable.Routes);
}