Remove MVC URL parameter name

Asked

Viewed 247 times

0

I have the following URL

/vlog/usertimeline/? Slug=tests

for the Vlog controller, usertimeline action and Slug parameter. How should I set the route to stay

/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 = "" }

            );
  • set up some route?

  • for this controller I have nothing. there are some routes to other controllers/methods, but they were already in the project I am working on.

  • will have to create a route so that he can do this, and also check the sets of routes if there are no equal. how to put the route file in your question? and the respective controller/action ?

  • Unfortunately I cannot paste the code here, since it is a product that is not exclusively mine. What is the logic that is used to hide this Slug? my method is like this: public ActionResult usertimeline(string slug = "")

  • Without sharing the code it is difficult to help, but try using the [Route("")] attributes to configure.

  • You can use it as a base: Routes.Maproute( "Company", // Route name "{controller}/{action}/{Slug}", // URL with Parameters new { controller = "Company", action = "Index", id = "" } // Parameter defaults&#xTo; );

Show 1 more comment

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 = ".+" }
        );
  • I put its implementation but it didn’t work, I edited the question and put all routes

  • @ihavenokia their routes already have problems they are repeating routes, but say there what did not work

  • if I don’t put ? Slug= never reaches the method, it doesn’t seem to recognize that what comes is Slug, if I don’t specify..

  • What is the Controller and the @ihavenokia method

  • Vlogcontroller Usertimeline

  • @ihavenokia my answer is correct has no where, although in your routas file have two equal routes Company and Default, can not.

  • the default route has to be the last, as the URL's "marry" her, I believe that’s why I’m not coming in. In case, as has two defaults both should be last

  • The big problem @Barbetta and that its routes also do not follow a pattern, despite its detail still can not have two equal routes, and this is happening.

Show 3 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.