ASP.NET MVC - passing parameters to the controller

后端 未结 10 1326
小蘑菇
小蘑菇 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条回答
  •  猫巷女王i
    2020-11-29 00:02

    There is another way to accomplish that (described in more details in Stephen Walther's Pager example

    Essentially, you create a link in the view:

    Html.ActionLink("Next page", "Index", routeData)
    

    In routeData you can specify name/value pairs (e.g., routeData["page"] = 5), and in the controller Index function corresponding parameters receive the value. That is,

    public ViewResult Index(int? page)
    

    will have page passed as 5. I have to admit, it's quite unusual that string ("page") automagically becomes a variable - but that's how MVC works in other languages as well...

提交回复
热议问题