I am trying to follow this example http://demos.telerik.com/aspnet-mvc/grid/editing-custom to display dropdown when user clicks on grid cell. However everytime when i view the grid, it only shows text 'undefined' instead of the actual dropdownlist.
Here is what i did:
ViewModel:
public class CommonDetailsViewModel
{
public List<
UOMItem
> UOMs { get; set; }
}
public class UOMItem
{
public string UserDefinedCode {get; set;}
}
Controller:
CommonDetailsViewModel commonDetailsViewModel = commonService.InvokeGetCommonDetails(flag);
var uomList =
new
SelectList(commonDetailsViewModel.UOMs,
"UserDefinedCode"
,
"UserDefinedCode"
);
ViewData[
"UOMList"
] = uomList;
ClientTemplates: Added UOM.cshtml inside 'Views/Shared/ClientTemplates' folder
@using System.Collections
@using Kendo.Mvc.UI;
@(Html.Kendo().DropDownList()
.BindTo((IEnumerable)ViewData["UOMList"])
.OptionLabel("- Select UOM - ")
.DataValueField("UserDefinedCode")
.DataTextField("UserDefinedCode")
)
View:
@(Html.Kendo().Grid<
SupplierPortal.ViewModels.CreateAsnRequestViewModel
>()
.Name("GridViewOpenPOSelected")
.Columns(columns =>
{
columns.Bound(p => p.UPCUOM).HtmlAttributes(new { @class = "editableFiled" }).ClientTemplate("#=UOM.UserDefinedCode#").Width(180);
})
.Editable(editable => editable.Mode(GridEditMode.InCell).DisplayDeleteConfirmation(false))
.AutoBind(false)
.Navigatable()
.DataSource(dataSource => dataSource
.Ajax()
.Batch(true)
.PageSize(10)
.Read(read => read.Action("GetSelectedPO", "Asn").Data("GetSelectedPOParameters"))
.ServerOperation(false)
.Model(model =>
{
model.Id(p => p.Id);
model.Field(p => p.UPCUOM).DefaultValue("EA");
}))
.Events(events => events.DataBound("gridDataBound"))
.Events(events => events.DataBinding("gridDataBinding"))
.Events(events => events.Edit("onEdit"))
)
Now everytime when i view the grid, the UPCUOM cell shows 'undefined'.
Any clue what am i doing wrong?
Thanks.