MVC Controller Action Parameter is null

asp.net-mvc, asp.net-mvc-3, asp.net-mvc-4

Solution

specific route you have to declare the first

routes.MapRoute(
            "DistrictDetails",
            "District/Incharges/{teamName}",
            new { controller = "District", action = "Incharges", id = UrlParameter.Optional }

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

Problem

I have Controller name: District and Action name: Incharges But I want the URL to be like this (action name with some paremeter) www.example.com/district/incharges/aaa www.example.com/district/incharges/bbb www.example.com/district/incharges/ccc But, while debugging teamName always return as NULL in the action parameter. Routing ``` routes.MapRoute( name: "Default", url: "{controller}/{action}/{id}", defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional } ); routes.MapRoute( "DistrictDetails", "District/Incharges/{teamName}", new { controller = "District", action = "Incharges" } ); ``` Controller But, while debugging teamName always return as NULL in the action parameter. ``` public class DistrictController : Controller { public ActionResult Incharges(string teamName) { InchargePresentationVM INPVM = new InchargePresentationVM(); INPVM.InitializePath(teamName, string.Empty); return View("", INPVM); } } ``` View ``` @{ ViewBag.Title = "Index"; } <h2>Index About</h2> ```

Original source