In my ASP.Net MVC 4 project, I have a controllers in a sub-folder in controller folder-
/Controllers
/GroupA
/AbcController.cs
In AbcController, i have two methods-
public ActionResult Index()
{
return View();
}
public ActionResult Edit(string value)
{
ViewBag.Message = value;
return View();
}
RouteConfig.cs -
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "TestRoute",
url: "GroupA/{controller}/{action}/{id}",
defaults: new { controller = "AbcController", action = "Index", id = UrlParameter.Optional }
);
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
}
but when i browse http://localhost:2240/groupa/abc/edit/somevalue
, 'somevalue' is not passed to the method. It shows null.
What i am missing here?
.../groupa/abc/edit?somevalueas url or changingpublic ActionResult Edit(string value)topublic ActionResult Edit(string id)i.e. you name your parameteridin the route, butvaluein the methodAreais the way to go. Before I also used the way OP is doing, but only recently I learnt aboutAreasand it is very easy to use.