asp.net mvc - How to load the record page wise from database in MVC? -
i developing mvc application. have around 8000 records in database.
i have used mvc.grid display these records. problem is, load 8000 records in controllers method. want fetch page wise or part of records, 100 records each time...
how ?
public actionresult index(int? page, string searchcontent = "") { productservice productservice = new productservice(); var pagenumber = (page ?? 1); var pagesize = 15; int id = convert.toint32(session["loggedempid"]); commonservice.setemployeeid(id); productservice productservice = new productservice(); var productlist = productservice.getproductinventory(); locationservice locationservice = new locationservice(); var loclist = locationservice.getall().where(x => x.type != locationtypedto.ho).tolist(); viewbag.loc = loclist; viewbag.searchcontent = searchcontent; homecoming view(productlist.topagedlist(pagenumber, pagesize)); } public ienumerable<productdto> getproductinventory() { list<productdto> productdtolist = new list<productdto>(); unitofwork uow = new unitofwork(); ienumerable<product> productlist = uow.productrepo.getinventorylist(); foreach (product product in productlist) { productdto productdto = transform.product2dto(product); productdtolist.add(productdto); } homecoming productdtolist; }
in 99% percent shouldn't show 8000 records.
you should utilize pagination. should 100 record in action , display it.
update: have confusing , wrong code. should utilize take() , skip() request.
i don't know topagedlist method
asp.net-mvc asp.net-mvc-3
No comments:
Post a Comment