AjaxList Demo





    by default the AjaxList will try to get data from the Search action of a controller with same name as it + "AjaxList" but a different Url or controller can be specified using .Url or .Controller extensions

    AjaxListDemo.aspx
    <% TxtSearch.TextBox().CssClass("searchtxt").Placeholder("search..."); %>
    <awe:Ocon runat="server" ID="TxtSearch" />
    <br />
    <br />
    <% Meals.AjaxList()
    .Url(Page.Url().Action("Search", "MealsAjaxList"))
    .Parent(TxtSearch.ClientID); %>
    <awe:Ocon runat="server" ID="Meals" />
    Awesome/AjaxList/MealsAjaxListController.cs
    public class MealsAjaxListController : Controller
    {
    public ActionResult Search(int page, string parent)
    {
    const int PageSize = 5;
    parent = (parent ?? "").ToLower();

    var list = Db.Meals.Where(o => o.Name.ToLower().Contains(parent));

    return Json(new AjaxListResult
    {
    Items = list.Skip((page - 1) * PageSize).Take(PageSize).Select(o => new KeyContent(o.Id, o.Name)),
    More = list.Count() > page * PageSize // bool - show More button or not
    });
    }
    }



    Comments