I defined the below routes to have friendly urls in my RouteConfig.cs:
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "CreateChildRoute",
url: "Admin/MaterialPaymentRequestSbuItem/CreateChild/{parentId}",
defaults: new { controller = "MaterialPaymentRequestSbuItem", action = "CreateChild", parentId = UrlParameter.Optional }
);
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional },
namespaces: new[] {"ProjectManager.Controllers"}
);
However when I call: http://localhost:46813/Admin/MaterialPaymentRequestSbuItem/CreateChild/23
A null value is passed to controller:
public ActionResult CreateChild(int? parentId){
.....
}
But calling http://localhost:46813/Admin/MaterialPaymentRequestSbuItem/CreateChild?parentId=32
Works with no problem and passes the parameter as it supposed to be.
P.S. Admin is a defined area in my application.
Here is output of Route Debugger for http://localhost:46813/Admin/MaterialPaymentRequestSbuItem/CreateChild?parentId=2:

.../CreateChild?parentId=32), as an example:@Html.ActionLink("Create New Item", "CreateChild", new { parentId = @ViewBag.ParentID }, null)@Html.ActionLink("Create New Item", "CreateChild", "MaterialPaymentRequestSbuItem", new { parentId = @ViewBag.ParentID }, null)which will work fine and generate..../Admin/MaterialPaymentRequestSbuItem/CreateChild/23. If its not, then there is something else you have not shown us causing the problem....?parentId=32instead of.../32? (I cant reproduce that)