How to generate hyphen url in MVC 4.net

I am currently working on a Visual Studio 2012 release to develop my website www.onlinegk.com using MVC 4. But I have a problem and you are looking for help from my expert on this problem. The problem is that I want my whole URL to be as follows:

www.onlinegk.com/current-affairs/
www.onlinegk.com/employment-news/
www.onlinegk.com/general-knowledge/latest-whos-who

But I do not get the proper help how to implement it, it means what will be the structure of the controller, and what will be the name of the view, etc. Please view the routeconfig.cs file as follows:

public static void RegisterRoutes(RouteCollection routes) { routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); routes.MapRoute( name: "Default", url: "{controller}/{action}/{id}", defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional } ); } 

I will be very grateful for your kind help.

+6
source share
1 answer

Try this for dynamic URLs:

 routes.MapRoute( "RouteName", "controler-name/{action}/{id}", new { controller = "ControllerName", action = "Index", id = "" } ); 
0
source

All Articles