简体   繁体   中英

pass method parameter from model to controller

public List<ProductlistModel> GetProductList(int catId)
{
   List<ProductlistModel> products = db.ProductLists.Where(c=>c.CategoryID==catId).Select(s => new ProductlistModel()
}

This is my product repository in Business Logic. I am trying to pass catId in controller but it is throwing error.

private ProductRepository pr = new ProductRepository();

public ActionResult Index()
{
    List<ProductlistModel> products = pr.GetProductList(catId);
    return View(products);
}

How to access catId in controller?

For example:

public ActionResult Index(int? catId)
{
    // TODO: check catId for null
    List<ProductlistModel> products = pr.GetProductList(catId.Value);
    return View(products);
}

Pass catId as parameter. You can handle it by passing parameter as string and convert it to int before passing to the Function or Procedure of Model

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