Problem redirecting page by route

Asked

Viewed 593 times

1

These are the routes

{
        routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

        routes.MapRoute(
           name: "Pacotes",
           url: "Passo/{name}",
           defaults: new { controller = "Passo", action = "Passo_01", name = "" }
       );

        routes.MapRoute(
           name: "RotaConteudo",
           url: "Conteudo/{name}/{Parametro}/{tipo}",
           defaults: new { controller = "Conteudo", action = "Conteudo", name = "", Parametro = "", tipo = "" }
       );

        routes.MapRoute(
           name: "RotaPasso_6",
           url: "Passo/{name}",
           defaults: new { controller = "Passo", action = "Passo_6", name = "" }
       );

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

In my controller there are two Actionresult: Passo_01 and Passo_06.

This is the call in the Index of Passo_06

<button id="btnGravarPassageiros" onclick="window.location.href='/Passo/Passo_06'" value="novaPesquisa" class="btn-pular-passo pull-right">Ir para o passo 06</button>

What happens is that I click the button to go to Passo_06, and it redirects me to Passo_01. If I comment on the routes, it works. What else should I do?

1 answer

1

You can use the UrlHelper to help you create urls in your view:

Url.Action("Passo_06", "Passo")

Exemplifying the use:

<button
    id="btnGravarPassageiros"
    onclick="window.location.href='@Url.Action("Passo_06", "Passo")'"
    value="novaPesquisa" class="btn-pular-passo pull-right">Ir para o passo 06</button>
  • Okay, buddy, keep coming to Action Passo_01 and not Passo_06. I did as an example.

  • The problem is in your routes. You are using the same url (url: "Passo/{name}") so much for the action Passo_01 as for the action Passo_06. The url should be different, something like Passo/1/{name} and Passo/6/{name}.

  • Man, thanks a lot. It worked!!! That’s right. But one for "good practices", ehehehehehehehe.

  • You can mark this answer as the solution of the problem then! That way, people will know it’s settled, plus I get a few points. = D

  • As I mark an answer?

  • There is a sign below the arrows to vote, like a " ", when you click this " " it will be filled with green.

Show 1 more comment

Browser other questions tagged

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