MVC Page not showing up, 404 not found

18,530

Solution 1

I think the URL should be:

/Other

not

/Views/Other/Index.aspx

The URLs are not typically prefixed with /Views. This is just the folder in which views are located. Also typically the View Index is not specified since this is the default action. Finally the extension .aspx is usually not specified in MVC. If you want this page to come up as the site's default page, you need to change your routing rules to look like this:

routes.MapRoute(
    "Default", // Route name
    "{controller}/{action}/{id}", // URL with parameters
    new { controller = "Other", action = "Index", id = UrlParameter.Optional}  // Parameter defaults
);

(notice the change of the default controller from Home to Other)

Solution 2

Is there any special URL or route specified in the Project Properties dialog?

This needs to be a route or URL, and not an .aspx page.

alt text

Solution 3

The 404 message seems to suggest you are trying to access the view directly in the web browser. Is this correct? Shouldn't you be accessing the url /Other/Index?

Share:
18,530
mwright
Author by

mwright

Objective C

Updated on June 04, 2022

Comments

  • mwright
    mwright almost 2 years

    I have a very simple MVC site that is returning a 404 not found error when trying to load a page at the very beginning. I'm looking for some direction to troubleshoot this problem since there is really nothing to go on from the error message.

    UPDATE: The problem appears to have been cause by me setting the start page by right-clicking on the file and saying set as start page. This caused Visual Studio to try to load that page directly. When modifying the url to access the page using the routing rules the page will load correctly as suggested by Keltex below.

    The error I'm getting is:

    Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable. Please review the following URL and make sure that it is spelled correctly.

    Requested URL: /Views/Other/Index.aspx

    Below I have included the code for the various pieces, routing rules are default:

    routes.MapRoute(
        "Default", // Route name
        "{controller}/{action}/{id}", // URL with parameters
        new { controller = "Home", action = "Index", id = UrlParameter.Optional}  // Parameter defaults
    );
    

    The site is using nested MasterPages, not sure if this is involved with the problem but trying to include as much detail as possible.

    I have:

    Controllers

    • OtherController

    Views:

    • Shared Folder:
      • Site.Master
    • Other Folder:
      • Other.Master
      • Index.aspx

    Site.Master Code:

    <%@ 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 Code:

    <%@ 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>
    

    Index.aspx Code:

    <%@ 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 Code

    namespace MVCProject.Controllers
    {
        public class OtherController : Controller
        {
            //
            // GET: /Member/
    
            public ActionResult Index()
            {
                // Have also tried:
                // return View("Index", "Other.Master");
    
                return View();
            }
        }
    }
    
  • mwright
    mwright about 14 years
    Modifying the url that I was accessing in the browser causes the page to load.
  • tuutuutuut
    tuutuutuut about 14 years
    @mwright. The URL you use when first starting your application. Or make the change to the routing I put above so your Other controller is the default controller.
  • mwright
    mwright about 14 years
    Yes, this had been modified when I right-clicked on the page and said set as start page. I changed it to point to the "Other" folder and modified the routing rules to use the "OtherController" as well. Thanks.