0

Check the code bellow. Here in route i want to give user enter input of username in url just like example.com/username but problem with that RouteConfig.cs is this cant take input like that. This will only take controller/method format. Please advice me how can i achieve domain/username type input form user? I want to serve that request from Test method bellow

Currently RouteConfig.cs file:

public class RouteConfig
    {
        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 }
            );
        }
    }

Test method:

public ActionResult Test(String username)
        {
            return View();
        }
Vivek Nuna
  • 25,472
  • 25
  • 109
  • 197
Mr John
  • 119
  • 7

1 Answers1

0

Try this.

routes.MapRoute("Id"
              , "{id}"
                , new { controller = "Home", action = "Test"});
Vivek Nuna
  • 25,472
  • 25
  • 109
  • 197