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?