ASP.NET MVC - passing parameters to the controller

后端 未结 10 1322
小蘑菇
小蘑菇 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:12

    you can change firstItem to id and it will work

    you can change the routing on global.asax (i do not recommed that)

    and, can't believe no one mentioned this, you can call :

    http://localhost:2316/Inventory/ViewStockNext?firstItem=11
    

    In a @Url.Action would be :

    @Url.Action("ViewStockNext", "Inventory", new {firstItem=11});
    

    depending on the type of what you are doing, the last will be more suitable. Also you should consider not doing ViewStockNext action and instead a ViewStock action with index. (my 2cents)

提交回复
热议问题