mardi 29 décembre 2015

MVC page not loading - The resource cannot be found

I just created an empty MVC project and added a masterpage and 1 view(Index). I also created a Controller(HomeController). I also right clicked on Index.aspx view and set this as startup.

However and error is showing up when running the project - "Server Error in '/' Application. The resource cannot be found. Requested URL: /Views/Index.aspx"

HomeController

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

Index

<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server">

<h2>Index</h2>

</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="head" runat="server">
    Test
</asp:Content>

MasterPage

<html xmlns="http://ift.tt/lH0Osb">
<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>

Global

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

Aucun commentaire:

Enregistrer un commentaire