Oblomov
Oblomov

Reputation: 9635

Migrate a RouteConfig file from ASP.Net MVC 4 to 5

The following RouteConfig worked in ASP.NET MVC 4:

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

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

            routes.MapRoute(
                name: "Default",
                url: "{controller}/{action}/{id}",
                defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
            );
        }
    }

In ASP.Net MVC 5, the statement

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

generates the error

Error   CS1503  Argument 3: cannot convert from '<anonymous type: string controller, string action, string name>' to 'string'   

Apparently, the signature of MapRoute has changed.

How can I migrate the code to ASP.Net MVC 5 ?

Upvotes: 1

Views: 61

Answers (1)

Lord Darth Vader
Lord Darth Vader

Reputation: 2005

Try this

routes.MapRoute(
            name: "Cuisine",
            url: "cuisine/{name}",
            defaults: new {controller = "Cuisine",action = "Search", name = UrlParameter.Optional});

Upvotes: 2

Related Questions