AjaxList Client Side API
-
$('#MealsApiDemo').data('api').load( { params: { meal : 'o' } });
-
$('#MealsApiDemo').data('api').load( { params: { meal : 'Mango' } });
-
$('#MealsApiDemo').data('api').load( { params: { pageSize : 3 } });
Awesome/AjaxList/MealsApiDemoAjaxListController.cs
using System.Linq;
using Microsoft.AspNetCore.Mvc;
using AweCoreDemo.Models;
using Omu.AwesomeMvc;
using System.Threading.Tasks;
using AweCoreDemo.Data;
using AweCoreDemo.Utils;
namespace AweCoreDemo.Controllers.Awesome.AjaxList
{
public class MealsApiDemoAjaxListController : Controller
{
private readonly MyContext mcx = new MyContext();// mock EF Db context
public MealsApiDemoAjaxListController()
{
}
public async Task<IActionResult> Search(int page, int pageSize = 5, string meal = "")
{
var query = mcx.Meals.Where(o => o.Name.Contains(meal));
var count = await query.CountAsync();
var items = await AweUtil.GetPage(query, page, pageSize).ToListAsync();
return Json(new AjaxListResult
{
Items = items.Select(o => new KeyContent(o.Id, o.Name)),
More = count > page * pageSize // bool - show More button or not
});
}
}
}
Comments