Search code examples
asp.net-mvctelerikkendo-grid

How do I access a ViewModel field from Kendo Grid MVC column definition?


How do I access the c => c.IsExpired field down below in place of the >>> ISEXPIRED <<< placeholder?

@(Html.Kendo().Grid<Corporate.Models.OrderModel>()
    .Name("ordersGrid")
    .Columns(columns =>
    {
        columns.Template(@<text></text>)
            .ClientTemplate(AdminDeleteEditTemplate().ToHtmlString())
            .Visible(isAdmin)
            .Width(110);

        columns.Bound(c => c.OrderID)
            .ClientTemplate(Html.ActionLink("#= OrderID #", "Details", "Orders", new { id = "#= OrderID #" }, new { }).ToHtmlString())
            .HtmlAttributes(new { @class = "text-right" });

        columns.Bound(c => c.ResellerName).ClientTemplate("#= ResellerID ? ResellerName : '' #");

        columns.Bound(c => c.Date).Format("{0: MMM d, yyyy}").HtmlAttributes(new { @class = "text-right" });

        columns.Bound(c => c.ExpirationDate)           
            .ClientTemplate("#= IsExpired == false ? kendo.toString(kendo.parseDate(ExpirationDate), 'MMM d, yyyy').concat(IsExpiringSoon ? '<small> (expiring soon)</small>' : '') : '' #")
            .HtmlAttributes(new { @class = "text-right" });

        columns.Bound(c => c.StringList)
            .Template(@<text></text>)
            .ClientTemplate("#= renderActions(data) #")
            .Title("Actions")
            .Visible(!Model.HideOptions);

    columns.Template(@<text></text>)
            .ClientTemplate(AdminOthersTemplate(>>> ISEXPIRED <<<).ToHtmlString())
            .Visible(isAdmin);

    })
    .Events(e => e.DataBound("onOrdersDataBound"))
    .Sortable()

Solution

  • Try to pass the data object to the template function

    columns.Template(@<text></text>)
            .ClientTemplate("#= AdminOthersTemplate(data) #")
            .Visible(isAdmin);
    

    and

    AdminOthersTemplate(data){
        console.log(data.IsEscaped);
    }