Awesome ASP.net Core and MVC Controls

AjaxList Custom Item Template


    To use custom item template in the controller instead of setting the Items property you have to set the Content property with the prerendered html content.
    RenderView is a controller extension from Omu.AwesomeMvc that renders a view and returns the result as a string.
    The view that gets rendered must consist from 'li' tags (or 'tr' if using TableLayout) with class="awe-li" and data-val=key attributes
    AjaxListDemo/CustomItemTemplate.cshtml
    @Html.Awe().AjaxList("MealsCustomItem")
    Awesome/AjaxList/MealsCustomItemAjaxListController.cs
    public class MealsCustomItemAjaxListController : Controller
    {
    public ActionResult Search(int page)
    {
    const int PageSize = 5;
    return Json(new AjaxListResult
    {
    Content = this.RenderView("CustomItem", Db.Meals.Skip((page - 1) * PageSize).Take(PageSize).ToList()),
    More = Db.Meals.Count > (page * PageSize)
    });
    }
    }
    MealsCustomItemAjaxList/CustomItem.cshtml
    @using AwesomeMvcDemo.Models
    @{
    Layout = null;
    }
    @model IList<Meal>

    @foreach (Meal meal in Model)
    {
    <li class="awe-li" data-val="@meal.Id">
    Name: @meal.Name
    <br />
    Category: @meal.Category.Name
    <br />
    Description: @meal.Description
    </li>
    }



    Comments

    We use cookies to improve your online experience. By accessing this site, you agree to the use of cookies and other technologies to process your personal data (e.g. IP address) to enhance and personalise your experience across our websites. Additionally, third-party companies, may store cookies on your device and use similar technologies to collect and use certain information. For more information, refer to our privacy policy and cookie policy.