ASP.net
Awesome
Learn
Forum
Buy
Demos
Sign In
☾
☀
Switch to
Dark
Light
Mode
this site works best with javascript enabled
Ask Question
Problem with Grid action - Count must have a non-negative value
Title:
B
I
{code}
?
Making call to the controller action always give error for GridModelBuilder: Count must have a non-negative value. Parameter name: count. @(Html.Awe().Grid(gridId) .Url(Url.Action("AjaxTest", "tickets")) ... Controller: public ActionResult AjaxTest(GridParams g) { var items = db.tickets.Take(200); var model = new GridModelBuilder<ticket>(items, g) { Key = "id", Map = MapTickets }.Build(); return Json(model); }
Save Changes
Cancel
Vladimir Kerzhentsev
asked at 04 Oct 2019
the `GridModelBuilder` will `OrderBy` key ("id" in your case), and use `Skip` and `Take` for paging, do you get the same error if you don't call `Take(200)` ?
at 04 Oct 2019
Omu
without Take(200) - everything works correctly.
at 05 Oct 2019
Vladimir Kerzhentsev
think if you will call `.ToList()` after `Take(200)` it will work, the grid is already doing paging so you shouldn't need to call `Take(200)`, perhaps an alternative for you would be to edit the model returned by GridModelBuilder and cap the number of pages var model = new GridModelBuilder(...).BuildModel(); model.PageCount = model.PageCount > 10 ? 10 : model.PageCount; return Json(model.ToDto()); I'm guessing this is what you want
at 05 Oct 2019
Omu
Answers
please
Sign In
to leave an answer
By accessing this site, you agree to store cookies on your device and disclose information in accordance with our
cookie policy
and
privacy policy
.
OK