Lookup
Pick a meal:
Lookup needs a controller or urls to be specified, by default convention the lookup
will look for a controller with the same name as it + "LookupController"
-
action GetItem
- used to show the value in the readonly field, it will receive av
parameter which is going to be the key of the selected item -
action Search
- gets data for the search result in it's popup, it should return aJson(AjaxListResult)
, so it has same features as the AjaxList (table layout, custom item template)
LookupDemo/IndexContent.cshtml
@(Html.Awe().LookupFor(o => o.Meal)
.Controller<MealLookupController>()
.ClearButton(Model.ClearButton)
.HighlightChange(Model.HighlightChange)
.Fullscreen(Model.Fullscreen))
Awesome/Lookup/MealLookupController.cs
using System.Linq;
using Microsoft.AspNetCore.Mvc;
using AweCoreDemo.Models;
using AweCoreDemo.Utils;
using Omu.AwesomeMvc;
using System.Threading.Tasks;
using AweCoreDemo.Data;
using AweCoreDemo.Utils.Awesome;
namespace AweCoreDemo.Controllers.Awesome.Lookup
{
public class MealLookupController : Controller
{
private readonly MyContext mcx = new MyContext();// mock EF Db context
public MealLookupController()
{
}
public async Task<IActionResult> GetItem(int? v)
{
Check.NotNull(v, "v");
var o = await mcx.FindAsync<Meal>(v) ?? new Meal();
return Json(new KeyContent(o.Id, o.Name));
}
public async Task<IActionResult> Search(int page, string search = "")
{
var query = mcx.Meals.Filter(search, o => o.Name);
var res = await EFAweUtil.BuildListAsync(query, page, keyContentFunc: o => new KeyContent(o.Id, o.Name));
return Json(res);
}
}
}
Comments