MultiLookup needs a controller or urls to be specified, by default convention it
will look for a controller with the same name as it + "MultiLookupController"
action GetItems - used to show the value in the readonly field, it
will receive a v parameter which is going to be the keys of the selected
items
action Search - gets data for the search result in it's popup, it receives
a selected parameter that represents the selected values, it should
return a Json(AjaxListResult), so it has same features as the AjaxList
(table layout, custom item template)
action Selected - gets data for the selected items in the popup
using AweCoreDemo.Data; using AweCoreDemo.Models; using AweCoreDemo.Utils.Awesome; using Microsoft.AspNetCore.Mvc; using Omu.AwesomeMvc; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks;
namespace AweCoreDemo.Controllers.Awesome.MultiLookup { public class MealsMultiLookupController : Controller { private readonly MyContext mcx = new MyContext();// mock EF Db context
public MealsMultiLookupController() {
}
public async Task<IActionResult> GetItems(int[] v) { var items = new List<Meal>();
if (v != null) { items = await mcx.Meals .Where(o => v.Contains(o.Id)).ToListAsync(); }
return Json(items.Select(meal => new KeyContent(meal.Id, meal.Name))); }
public async Task<IActionResult> Search(int[] selected, int page, string search) { selected = selected ?? new int[] { };
var query = mcx.Meals.Filter(search, o => o.Name).Where(o => !selected.Contains(o.Id));
var res = await EFAweUtil.BuildListAsync(query, page, keyContentFunc: o => new KeyContent(o.Id, o.Name ));
return Json(res); }
public async Task<IActionResult> Selected(int[] selected) { var items = new List<Meal>();