1

I have a question about MVC3 in the Pluralsight examples. I'm new to MVC and I have what will appear to be a simple question. I downloaded the sample code and added the Routemap to global.asax.cs:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;

namespace OdeToFood
{
    // Note: For instructions on enabling IIS6 or IIS7 classic mode, 
    // visit http://go.microsoft.com/?LinkId=9394801

    public class MvcApplication : System.Web.HttpApplication
    {
        public static void RegisterGlobalFilters(GlobalFilterCollection filters)
        {
            filters.Add(new HandleErrorAttribute());
        }

        public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

            routes.MapRoute(
                "Cuisine",
                "cuisine/{name}",
                new { controller = "cuisine", action = "Search" }
                );

          /*  routes.MapRoute(
                "Cuisine",
                "{controller}/{name}",
                new { controller = "cuisine", action = "Search" }
                ); */


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

            RegisterGlobalFilters(GlobalFilters.Filters);
            RegisterRoutes(RouteTable.Routes);
        }
    }
}

And added the Controller:

namespace OdeToFood.Controllers
{
    public class CuisineController : Controller
    {
        //
        // GET: /Cuisine/

        public ActionResult Search()
    {
        return Content("You have reached the Cuisine controller");
    }
}

}

As shown in the tutorial "Controller Action Parameter!" and run the application with the word cuisine (all spelled correctly - even changing to all capitalization as a test) and I still get the HTTP 404 "not found error".

I'm running on Windows 7 with VS 2012 and .net 4.5 installed (this is a new box and may not have ever had previous versions. MVC 3 and MVC 4 are in the new project selection so those must be isntalled correclty.

Any ideas on what I'm doing wrong? Did I miss a step? I see that IIS6 or IIS7 might/must be on the machine? I have come to believe that IIS doesn't run on windows 7. Is that true? Do I require iis? The sample code works fine until this change...

I'm a little over my head here as I learn this new stuff. Thank you for your patience and help!

icedwater
  • 4,701
  • 3
  • 35
  • 50
  • Is your `Search` method in your `CuisineController` is called ? Try to put a breakpoint and take a look. If it not the case, you probably have a mistake with your project architecture, which can be strange if you're not familiar with MVC – AlexB Nov 19 '13 at 15:35
  • Possible duplicate: http://stackoverflow.com/questions/705229/diagnosing-404-errors-on-iis-7-and-asp-net-mvc ? – Carsten Nov 19 '13 at 15:36
  • The search method is never called. The route is mapped but never reached when "cuisine" is entered into the address bar:http://localhost:49237/cuisine. (I changed everything back to proper upper/lower case to match the sample code.) I tried the techniques in the other thread and those do not fix the issue either. – Richard Howes Nov 19 '13 at 15:56
  • Can you post the content of the `Application_Start()` method in _Global.asax_? – Alex Filipovici Nov 19 '13 at 15:58
  • I cannot edit my comment so I will add... I was wishing and dreaming that someone had the exact same problem. – Richard Howes Nov 19 '13 at 16:02
  • Thank you Alex... I'll post the entrie file because it is not very big... – Richard Howes Nov 19 '13 at 16:14
  • added entire file to oroginal post. thanks again. – Richard Howes Nov 19 '13 at 16:15
  • FYI. the original project was created in VS2010 and I am opening them in VS2012 which has some upgrading going on... – Richard Howes Nov 19 '13 at 16:36
  • Thanks for everyones help and advice. I'm moving on. – Richard Howes Nov 19 '13 at 18:25

2 Answers2

2

Try using:

routes.MapRoute(
    "Cuisine",
    "cuisine/{name}",
    new { controller = "cuisine", action = "Search", name = "" }
    );
Alex Filipovici
  • 31,789
  • 6
  • 54
  • 78
  • This did not work. I get the same 404 error. 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: /cuisine -------------------------------------------------------------------------------- Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.18055 – Richard Howes Nov 19 '13 at 15:56
1

Try using the a MVC Route Debugger so that you can visually see which routes are being matched. The one I use is Phil Haack's, but there are others available:

Install-Package RouteDebugger

Separately, don't you need a name parameter on your search action to match this route?

Simon
  • 6,062
  • 13
  • 60
  • 97