简体   繁体   中英

Parameter not being passed to Controller's action in ASP.NET MVC

I have two actions in a controller and yet the parameters are not being passed into one of them.

This one: /RouteStop/List/1

And this one: /RouteStop/Details/100

And my global.asax:

routes.MapRoute( "List", "{controller}/{action}/{id}", new { controller = "RouteStop", action = "List", id = UrlParameter.Optional } );

routes.MapRoute( "Details", "{controller}/{action}/{routeID}", new { controller = "RouteStop", action = "Details", routeID = UrlParameter.Optional } );

And here's the actions from my Controller:

public ActionResult List(string id) { return View(); }

public ActionResult Details(string routeID) { return View(); }

When I access this URL (/RouteStop/Details/100) the parameter gets passed just fine. But when I access the other one (/RouteStop/List/1) the parameter is null. The names match up as they should but I can't figure it out.

Try replacing {controller} with List and Details in respective routes. but for your scenario the default routing that you get when you create an MVC app should work.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM