我有一個非常簡單的MVC網站,當試圖在開始時加載頁面時返回404未找到錯誤。我正在尋找一些方向來解決這個問題,因爲從錯誤信息中沒有什麼可以繼續。MVC頁面沒有顯示,404沒有找到
更新:問題似乎是由於我通過右鍵單擊該文件並設置爲起始頁來設置起始頁的緣故。這導致Visual Studio嘗試直接加載該頁面。當修改url以使用路由規則訪問頁面時,頁面將按照Keltex的建議正確加載。
我得到的錯誤是:
說明:HTTP 404。您正在查找的資源(或它的 的一個依賴項)可能已被刪除,更名,或暫時無法使用 。請檢查以下URL並確保它正確拼寫 。
請求的URL:/Views/Other/Index.aspx
下面我包括爲各個部分的代碼,路由規則默認:
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = UrlParameter.Optional} // Parameter defaults
);
該網站使用嵌套MasterPages ,不確定這是否涉及問題,但試圖儘可能包含更多細節。
我:
控制器
- OtherController
瀏覽:
- 共享文件夾:
- 的Site.Master
- 其他文件夾:
- Other.Master
- 的Index.aspx
的Site.Master代碼:
<%@ Master Language="C#" Inherits="System.Web.Mvc.ViewMasterPage" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>
<asp:ContentPlaceHolder ID="TitleContent" runat="server" />
</title>
</head>
<body>
<div>
<asp:ContentPlaceHolder ID="MainContent" runat="server">
</asp:ContentPlaceHolder>
</div>
</body>
</html>
Other.Master代碼:
<%@ Master Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewMasterPage" %>
<asp:Content ID="OtherTitle" ContentPlaceHolderID="TitleContent" runat="server">
OTHER PAGE - MASTER TITLE
<asp:ContentPlaceHolder ID="OtherPageTitle" runat="server">
</asp:ContentPlaceHolder>
</asp:Content>
<asp:Content ID="OtherContent" ContentPlaceHolderID="MainContent" runat="server">
Some other content.
<asp:ContentPlaceHolder ID="PageContent" runat="server">
</asp:ContentPlaceHolder>
</asp:Content>
指數。ASPX代碼:
<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Other/Other.Master" Inherits="System.Web.Mvc.ViewPage" %>
<asp:Content ID="IndexTitle" ContentPlaceHolderID="OtherTitle" runat="server">
Home
</asp:Content>
<asp:Content ID="IndexContent" ContentPlaceHolderID="OtherContent" runat="server">
Index content
</asp:Content>
OtherController代碼
namespace MVCProject.Controllers
{
public class OtherController : Controller
{
//
// GET: /Member/
public ActionResult Index()
{
// Have also tried:
// return View("Index", "Other.Master");
return View();
}
}
}
修改我在瀏覽器中訪問的url會導致頁面加載。 – mwright 2010-03-31 22:02:24
@mwright。首次啓動應用程序時使用的URL。或者對上面的路由進行更改,使其他控制器成爲默認控制器。 – Keltex 2010-03-31 22:05:25