AjaxList

Renders a list and a load more button, in the controller on each request we set a property indicating whether there's is more items to be loaded.




    Shared/Demos/AjaxListBoundToParent.cshtml
    @(Html.Awe().TextBox(
    new TextBoxOpt
    {
    Name = "txtSearchMealsAl",
    CssClass = "searchtxt",
    Placeholder = "search..."
    }))
    <br />
    <br />
    @(Html.Awe().AjaxList("MealsAl")
    .Url(Url.Action("Search", "MealsAjaxList"))
    .Parent("txtSearchMealsAl"))
    Awesome/AjaxList/MealsAjaxListController.cs
    public class MealsAjaxListController : Controller
    {
    public IActionResult Search(string parent, int? pivot)
    {
    const int PageSize = 5;

    var query = Db.Meals.AsQueryable();

    query = query.Filter(parent, o => o.Name);

    var pageItems = (pivot.HasValue ? query.Where(o => o.Id >= pivot.Value) : query)
    .Take(PageSize + 1)
    .ToArray();

    var isMore = pageItems.Count() > PageSize;

    var result = new AjaxListResult
    {
    Items = pageItems.Take(PageSize).Select(o => new KeyContent(o.Id, o.Name)),
    More = isMore
    };

    if (isMore)
    {
    result.Pivot = pageItems.Last().Id;
    }

    return Json(result);
    }
    }



    Comments