I have a Kendo().Grid<>() that uses a MVC EditorTemplate to PopUp and allow the fields to be changed. When I type in the editor template all is well. However, if I update the field using .set('Field', 'Value') on a field that has the [Required] attribute set in C#, the set does not update the value.
Here is the ViewModel object definition:
public class SampleVM{ public int Id { get; set; } [Required] public string Foo { get; set; } public string Bar { get; set; }}Here is my Grid definition:
@(Html.Kendo().Grid<SampleVM>() .Name("cSampleGrid") .DataSource(ds => ds .Ajax() .Read(r => r.Action("IndexList", "Home")) .Create(c => c.Action("CreateIndex", "Home")) .Model(m => { m.Id(f => f.Id); } ) ) .ToolBar(t => t.Create().Text("Create Index")) .Editable(e => e.Mode(GridEditMode.PopUp)) .Events(e => e.Edit("OnEditSample")))@section Scripts {<script> function OnEditSample(pEvent) { var editDiv = pEvent.container; var editWindow = pEvent.container.data('kendoWindow'); var editable = pEvent.model; if (editable.ContactID == 0) editWindow.title = 'Create Index'; else editWindow.title = 'Edit Index'; editWindow.editable = editable; $('#cFillButton', pEvent.container).click(function (pEvent) { editWindow.editable.set('Foo', 'Foo'); editWindow.editable.set('Bar', 'Bar'); }); }</script>}Here is my editor template:
@model KendoRequiredBug.Models.SampleVM @Html.AntiForgeryToken() @Html.ValidationSummary(true, "", new { @class = "text-danger" }) <div class="field-label"> @Html.LabelFor(model => model.Foo, htmlAttributes: new { @class = "control-label col-md-2" }) </div> <div class="field-editor"> @Html.EditorFor(model => model.Foo, new { htmlAttributes = new { @class = "form-control" } }) @Html.ValidationMessageFor(model => model.Foo, "", new { @class = "text-danger" }) </div> <div class="field-label"> @Html.LabelFor(model => model.Bar, htmlAttributes: new { @class = "control-label col-md-2" }) </div> <div class="field-editor"> @Html.EditorFor(model => model.Bar, new { htmlAttributes = new { @class = "form-control" } }) @Html.ValidationMessageFor(model => model.Bar, "", new { @class = "text-danger" }) </div><div style="clear:both"></div><div><a id="cFillButton" class="k-button">Fill</a></div>When the Fill button is clicked, the Bar field is set properly, however the Foo field is left blank and the "Required field" error message is shown. If I remove the [Required] attribute from 'Foo', then both fields update as expected. I am using Kendo 2015.1.429.
Can anyone explain what is going on?