SetListUrl with parameter...

Jul 4, 2011 at 6:49 PM


My model have an ID ... I´d like to call SetListUrl with that ID...

What I have now :

public ActionResult List(SearchModel searchModel)
     var list = ...
     return Json(...)

I´d like to add my ID in List method...  Is that possible?




Jul 4, 2011 at 8:11 PM

You have to pass the ID into the SetListUrl for example:

new GridControl()
                cs.Add(x => x.ProductId).SetAsPrimaryKey();
                cs.Add(x => x.Name);
                cs.Add(x => x.CompanyName);
                cs.Add(x => x.Price);

In your List method the controller, you can add the ID as a parameter:

public ActionResult List(SearchModel searchModel, int ID)
            ProductRepository repository = new ProductRepository();

            List<Product> products = repository.ListAll().Where(p=>p.ProductId==ID).ToList();

            return Json(products.AsQueryable().ToGridData(searchModel, new[] { "Id", "Name", "CompanyName", "Price" }), JsonRequestBehavior.AllowGet);

Jul 4, 2011 at 8:21 PM



Worked fine...