views:

66

answers:

3

Basically what the title says. I created a new MVC application. I'm trying to add new pages to the site, but anytime I do I get the following error:

Server Error in '/' Application.
The resource cannot be found.
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: /Products

Here is my controller, called ProductsController.

namespace MyAppMVC.Controllers
{
    public class ProductsController : Controller
    {
        public ActionResult Index()
        {
            return View("Index");
        }
    }
}

I had also tried

            return View();

But that didn't work.

My view is called Index.aspx, and it's in the folder Views/Products.

So everything looks fine to me, I looked in the NerdDinners tutorial and they don't seem to do anything different than me either. I've looked at the home controller that comes with the app, and mine seems identical. I'm pretty sure I don't have to add anything to the routing, but maybe I do.

Any ideas? This has got me stumped.

As per request here is my global.asax.cs file

public class MvcApplication : System.Web.HttpApplication
{
    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);
    }
}
+4  A: 

Check your routing, using Phil Haack's route tester, and make sure your routes are properly routing to the desired controller methods.

Robert Harvey
I'll give this a shot. Thanks.
Duk
A: 

It might be that you are using IIS6 and have not enabled a wildcard mapping. Or you could have also not set up the default document to Default.aspx? Or deleted Default.aspx from the application root? :)

Artiom Chilaru
The IIS thing may be the case. I just installed MVC and went from there. Im running the app through visual studio currently.I checked and I have IIS7 though. Not sure how to setup wild card mapping.I haven't deleted the default file, and it seems to load fine as the other pages work that come with the app (Home and About and the login/register pages).
Duk
Well.. this makes it a lot more interesting.. In IIS7 you don't need the wildcard mapping, and if the other controllers work fine it means that the problem is in your app itself..Sometimes the weirdest of problems have the simplest of solutions.. You have rebuilt the solution before loading the page, right? ^_^
Artiom Chilaru
I had, the issue in the end was caused by master pages. Can see my answer above.Thanks for the help! :)
Duk
Very interesting, thanks for the update! I'll keep this in mind next time :)
Artiom Chilaru
A: 

The issue in the end was I had created an incorrect master page that had code behind files that were causing issues. I just failed to notice that MVC had it's own selection for Master Pages in the Add New dialogue. Oops!

Thanks for the help everyone.

Duk