Is it possible to dynamically generate routes in ASP.NET MVC4

0

I'm fixing some URL's for my site and I need to create several different routes for each page, for example:

routes.MapRoute(
    name: "ComoVenderMinhasImagens",
    url: "como-vender-minhas-imagens",
    defaults: new { controller = "Home", action = "ComoVenderMinhasImagens", id = UrlParameter.Optional }
);
routes.MapRoute(
    name: "PerguntasFrequentes",
    url: "perguntas-frequentes",
    defaults: new { controller = "Home", action = "PerguntasFrequentes", id = UrlParameter.Optional }
);
routes.MapRoute(
    name: "FormasdePagamento",
    url: "formas-de-pagamento",
    defaults: new { controller = "Home", action = "FormasdePagamento", id = UrlParameter.Optional }
);
routes.MapRoute(
    name: "BancoDeImagens",
    url: "banco-de-imagens",
    defaults: new { controller = "Home", action = "BancoDeImagens", id = UrlParameter.Optional }
);

As in the example, I need to create URL's in which words are separated by - in some cases, there is some tool of the framework itself that allows me to create a generic route that works for any type of Action regardless of the number of words?

(stock-image & amp; how-to-sell-my-pictures & amp; amp; amp;     

asked by anonymous 09.10.2018 / 16:03

1 answer

0

In your controller you only have to put route :

public class HomeController : Controller
{
   [Route("")]
   [Route("Home")]
   [Route("Home/Index-EXEMPLO")]
   public IActionResult Index()
   {
      return View();
   }
   [Route("Home/About-EXEMPLO")]
   public IActionResult About()
   {
      return View();
   }
   [Route("Home/Contact-EXEMPLO")]
   public IActionResult Contact()
   {
      return View();
   }
}

If you still have questions on the Microsoft website, explain this: TUTORIAL

    
09.10.2018 / 17:02