Remove parameter name URL MVC

0

I have the following URL

  

/ vlog / usertimeline /? slug = tests

for the Vlog controller, action usertimeline and slug parameter. How do I set the route to be

  

/ vlog / usertimeline / tests

I'm using MVC 4.

I have the following routes configured:

 routes.MapRoute(
            "PubServices",
            "PubServices/{action}",
            new { controller = "PubServices", action = "Index" });

        routes.MapRoute(
            "MailsJson",
            "MailsJson/{action}",
            new { controller = "MailsJson", action = "Index" });

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

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

        );

        routes.MapRoute(
            "RecoverPasswordFinish",
            "Account/RecoverPasswordFinish/{username}/{hash}",
            new { Controller = "AccountWF", action = "RecoverPasswordFinish" }
            );

        routes.MapRoute(
            "EmailConfirmation",
            "AccountWF/EmailConfirmation/{username}/{userid}",
            new { Controller = "AccountWF", action = "EmailConfirmation" }
            );

        routes.MapRoute(
            "UnsubscribeBulkEmail",
            "Mails/UnsubscribeBulkEmail/{id}",
            new { Controller = "Mails", action = "UnsubscribeBulkEmail", id = "" }
            );

        routes.MapRoute(

             "VlogTimeline",
             "Vlog/Timeline/{slug}",
             new { controller = "Vlog", action = "Timeline", slug = "" }

            );
    
asked by anonymous 22.03.2018 / 16:34

1 answer

2

To mount a specific route is as follows:

routes.MapRoute(
            "vlog_usertimeline_slug",
            "/vlog/usertimeline/{slug}",
            new { Controller = "Vlog", action = "UserTimeline", 
                  slug = UrlParameter.Optional }
            );

or

routes.MapRoute(
            name: "vlog_2",
            url: "/vlog/usertimeline/{slug}",
            defaults: new { controller = "Vlog", action = "TestUrl" } ,
            constraints: new { slug = ".+" }
        );
    
22.03.2018 / 16:58