The Search action of the LookupController returns json of AjaxListResult,
we need to set the string AjaxListResult.Content instead of Items in order to achieve
Custom Item Template, exactly the same as for the AjaxList helper.
<% MealCustomItem.Lookup()
.Controller("MealCustomItemLookup")
.CustomSearch(); %>
<awe:Ocon runat="server" ID="MealCustomItem" />
Awesome/Lookup/MealCustomItemLookupController.cs
using System.Linq;
using System.Web.Mvc;
using AwesomeWebFormsDemo.Data;
using AwesomeWebFormsDemo.Models;
using AwesomeWebFormsDemo.Utils;
using Omu.AwesomeWebForms;
namespace AwesomeWebFormsDemo.Controllers.Awesome.Lookup
{
public class MealCustomItemLookupController : Controller
{
public ActionResult SearchForm()
{
return PartialView();
}
public ActionResult GetItem(int? v)
{
Check.NotNull(v, "v");
var o = Db.Meals.SingleOrDefault(f => f.Id == v) ?? new Meal();
return Json(new KeyContent(o.Id, o.Name));
}
public ActionResult Search(string search, int page)
{
const int pageSize = 10;
search = (search ?? "").ToLower().Trim();
var list = Db.Meals.Where(f => f.Name.ToLower().Contains(search));
return Json(new AjaxListResult
{
Content = this.RenderPartialView("items", list.Skip((page - 1) * pageSize).Take(pageSize)),
More = list.Count() > page * pageSize
});
}
public ActionResult Details(int id)
{
return PartialView(Db.Get<Meal>(id) ?? new Meal());
}
}
}
\Views\MealCustomItemLookup/SearchForm.cshtml
@{ Layout = null; }
<input type="text" name="search" class="awe-searchtxt" placeholder="search..."/>
@(Html.Awe().InitPopup()
.Name("details")
.Url(Url.Action("Details"))
.Mod(o => o.OutClickClose())
.Modal())
\Views\MealCustomItemLookup/Items.cshtml
@model IEnumerable<AwesomeWebFormsDemo.Models.Meal>
@{ Layout = null; }
@foreach (var o in Model)
{
<li class="awe-li" data-val="@(o.Id)">Name: @o.Name
<button onclick="awe.open('details', { params: { id: @o.Id } }, event)" class="awe-btn awe-nonselect lkdetail" tabindex="-1">
Details
</button>
Category: @o.Category.Name
<br />
Description: @o.Description
</li>
}