Named parameters in url - asp.net

0

I'm having a problem with automatic url generation next to Asp.NET

I have the following code:

[RoutePrefix("c")]
[Route("{action=Index}")]
public class ConteudoController : BaseController
{
    [Route("{urlConteudo}")]
    public ActionResult Index(string urlConteudo){ ... }
    [Route("{urlMenu}/{urlConteudo}")]
    public ActionResult Index(string urlMenu, string urlConteudo) { ... }
}

At the moment of generating the url use the following code snippet

Url.Action("Index", "Conteudo", new { urlConteudo= "titulo-teste", urlMenu = "noticias" });

But the result of the named parameter is not as expected.

Expected:

  

/ c / noticias / titulo-teste

What you really had to exit:

  

/ c / title-test? urlMenu = news

Note: In my RouteConfig I have the mapping of route attributes

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

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

What exactly do I do to get the result of the named routes?

    
asked by anonymous 29.06.2017 / 16:35

1 answer

0

I'm going to use the answer field because I can not comment yet.

What you're doing with the snippet is sending two attributes through the URL, you can:

1- Use the attributes in this way (pull URL information into a variable):

Request.QueryString["atributo"];

2 - update your routeconfig.cs, try:

  new { area ="", controller = "Home", action = "Index" },
  new { area = "^$", controller = "Home", action = @"(Pagina1|Pagina2|etc..)"}
  new string[] { Home.Controllers }
    
29.06.2017 / 18:13