I have a grid like this:
@(Html.Kendo().Grid<
License
>()
.Name("popupGrid")
.Columns(columns =>
{
columns.Bound(p => p.LicenseId).Width(20).Hidden().HeaderHtmlAttributes(new { @title = "License" });
columns.ForeignKey(p => p.CustomerId, (System.Collections.IEnumerable)ViewData["customers"], "CustomerID", "CustomerName")
.Title("Customer").Width(200);
columns.Bound(p => p.VendorId).Width(20).HeaderHtmlAttributes(new { @title = "Vendor" });
columns.Bound(p => p.ProductId).Width(20).HeaderHtmlAttributes(new { @title = "Product" });
columns.Command(p => p.Edit().Text("Edit").HtmlAttributes(new { @title = "Edit" })).Width(80);
})
.ToolBar(toolbar => toolbar.Create().Text("Add").HtmlAttributes(new { @title = "Add" }))
.Editable(editable => editable.Mode(GridEditMode.PopUp).TemplateName("PopupEditView"))
.Events(e => e.Edit("onEdit"))
.DataSource(dataSource => dataSource
.Ajax()
.Model(model => model.Id(p => p.LicenseId))
.Create(create => create.Action("Create", "Home").Type(HttpVerbs.Post))
.Read(read => read.Action("Read", "Home").Type(HttpVerbs.Post))
.Update(update => update.Action("Update", "Home").Type(HttpVerbs.Post))
)
)
and PopupEditView.cshtml :
@(Html.Kendo().DropDownListFor(m => m.CustomerId).Name("CustomerId")
.ValuePrimitive(true)
.DataTextField("CustomerName")
.DataValueField("CustomerId")
//.OptionLabel("Select Customer...")
.DataSource(dataSource =>
{
dataSource.Read(read => read.Action("GetCustomers", "Home"))
.ServerFiltering(true);
})
)
@Html.ValidationMessageFor(m => m.CustomerId)
HomeController :
[HttpPost]
public
JsonResult Create([DataSourceRequest] DataSourceRequest request, License license)
{
if
(license !=
null
&& ModelState.IsValid)
// licence.CustomerId is null Model.State is not valid
{
LicenseRepository.Repository.Insert(license);
}
return
Json(
new
[] { license }.ToDataSourceResult(request, ModelState));
}
public
JsonResult GetCustomers()
{
return
Json(CustomerRepository.Repository.Customers, JsonRequestBehavior.AllowGet);
}
If .OptionLabel("Select Customer...") is commented and submit create then licence then CustomerId is null. If user change DropDownList(CustomerId) then it works fine.
Is this a bug?