ASP.NET MVC - passing parameters to the controller

后端 未结 10 1313
小蘑菇
小蘑菇 2020-11-28 23:36

I have a controller with an action method as follows:

public class InventoryController : Controller
{
    public ActionResult ViewStockNext(int firstItem)
           


        
10条回答
  •  北海茫月
    2020-11-29 00:16

    To rephrase Jarret Meyer's answer, you need to change the parameter name to 'id' or add a route like this:

    routes.MapRoute(
            "ViewStockNext", // Route name
            "Inventory/ViewStockNext/{firstItem}",  // URL with parameters
            new { controller = "Inventory", action = "ViewStockNext" }  // Parameter defaults
        );
    

    The reason is the default route only looks for actions with no parameter or a parameter called 'id'.

    Edit: Heh, nevermind Jarret added a route example after posting.

提交回复
热议问题