I have implemented inline editing with Knedo UI MVC grid with Ajax binding, Server side validation handled in controller and sending the error back using -
ModelState.AddModelError("Error: ", ex.Message);
@(Html.Kendo().Grid<AnalyticsServiceWeb.ViewModel.SomeViewModel>() .Name("Grid") .Columns(columns => { columns.Bound(p => p.Name); columns.Bound(p => p.Path); columns.Bound(p => p.Space); columns.Command(command => { command.Edit(); command.Destroy(); }); }) .ToolBar(toolbar => toolbar.Create()) .Editable(editable => editable.Mode(GridEditMode.InLine)) )
function error_handler(e) {
if (e.errors) {
var message = "Errors:\n";
$.each(e.errors, function (key, value) {
if ('errors' in value) {
$.each(value.errors, function () {
message += this + "\n";
});
}
});
alert(message);
}
}
The server side error message is getting displayed when there is a server side exception, but it still completes the action in UI, i mean it adds the new record to the grid and update as well even though there is server side exception.
Is there any way to retain the state of UI before the action start?, it supposed to work in that way, not sure if i am missing anything?
Thanks in advance
Using version 2012.3.1114.
This work using Visual Studio Development Server but does not show the drop down using IIS Express or IIS 7 on Windows Server 2008 R2
Code in view:
@(Html.Kendo().ComboBoxFor(m => m.ForPost) .Filter(FilterType.StartsWith) .DataTextField("label") .DataValueField("value") .MinLength(1) .DataSource(source => { source.ServerFiltering(); source.Read(read => { read.Action("AjaxPost", "Home"); //Set the Action and Controller name read.Type(HttpVerbs.Post); }); }))
[HttpPost]public ActionResult AjaxPost(string text) { if (string.IsNullOrWhiteSpace(text)) return Json(null); var x = Data.Where(d => d.StartsWith(text, StringComparison.InvariantCultureIgnoreCase)) .Select(d => new { label = d, value = d }).ToList(); return Json(x);}IE 9 in Javascript debug it shows this error "Microsoft JScript runtime error: Unable to get value of the property 'Errors': object is null or undefined" and pints the this dynamic code.
function anonymous(d) {return d.Errors}Using get works fine but our security people insist we use post for ajax.
Thanks,
Tom Wilkinson

public JsonResult GetCascadeCountries() { return Json(_db.Countries.Select(c => new {CountryId = c.Id, CountryName = c.CountryName }), JsonRequestBehavior.AllowGet); }
@(Html.Kendo().ComboBox() .Name("Countries") .Placeholder("Select a country") .DataTextField("CountryName") .DataValueField("CountryId") .DataSource(source => { source.Read(read => { read.Action("GetCascadeCountries", "Index"); }); }) )
if (elt.types[0] == 'country') { var countriesComboBox = $('#Countries').data("kendoComboBox"); alert($('#Countries_input').data()); var selectItem = function (dataItem) { //dataItem argument is a ComboBox data item. return dataItem.Text == elt.long_name; } countriesComboBox.select(selectItem); }
<div id="userGrid" data-role="grid" data-columns='[{ "field": "Name", "title": "Name"}, { "field": "Group", "title": "Group"}]' data-filterable='true' data-navigatable='true' data-pageable='true' data-groupable='true' data-sortable='true' data-bind="source: userDataSource"></div>and the DataSource is being set in javascript like this:
public ActionResult ListUsers([DataSourceRequest] DataSourceRequest request) { return Json(GetUsers().ToDataSourceResult(request)); }
@using Kendo.Mvc.UI;@model IEnumerable<OTIS.AppServ.Shared.ViewModels.ddlOptions>@(Html.Kendo().AutoComplete() .Name("TEST") .Filter("startswith") .DataTextField("DisplayName") .BindTo(Model) .Events(e => e .Change("autocomplete_change") ) .Placeholder("Select Customer...") .HtmlAttributes(new {@class = "filter"}) )<input class="filter" id="@ViewBag.ControlId" type="hidden" /><script> //$("#TEST").attr("id", '@ViewBag.ControlId' + '_org'); function autocomplete_change() { var hiddenInput = $('#' + '@ViewBag.ControlId'); var autoContainer = $("#" + 'TEST').data("kendoAutoComplete"); var result = $.grep(autoContainer.dataSource.data(), function (itemInArray, itemIndex) { return itemInArray.DisplayName == autoContainer.value(); } ); //alert(result[0].Id) hiddenInput.val(result[0].Id); }</script>[ChildActionOnly] public ActionResult Customers() { List<ddlOptions> viewModel = new List<ddlOptions>(); viewModel = _manageDDLsAppServ.GetCustomersDDLViewModel(_currentCompanyId).ToList(); ViewBag.ControlId = "customerIdFilter"; return PartialView("_ddlOptionsAutoComplete", viewModel); }@{ Html.RenderAction("Customers", "ManageDDLs", new { area = "Shared" }); }Compilation ErrorDescription: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately. Compiler Error Message: CS1977: Cannot use a lambda expression as an argument to a dynamically dispatched operation without first casting it to a delegate or expression tree typeSource Error:Line 8: .DataTextField("DisplayName")Line 9: .BindTo(Model)Line 10: .Events(e => e
.Change("autocomplete_change"))Line 11: .Placeholder("Select Customer...")Line 12: .HtmlAttributes(new {@class = "filter"})@using Kendo.Mvc.UI;@model IEnumerable<OTIS.AppServ.Shared.ViewModels.ddlOptions>@(Html.Kendo().AutoComplete() .Name(ViewBag.ControlId) .Filter("startswith") .DataTextField("DisplayName") .BindTo(Model) .Events(e => e
.Change("autocomplete_change")) .Placeholder("Select Customer...") .HtmlAttributes(new {@class = "filter"}) )<script> function autocomplete_change() { var autoContainer = $("#AutocompleteId").data("kendoAutoComplete"); var result = $.grep(autoContainer.dataSource.data(), function (item) { item.Text == autoContainer.value(); }); } </script>@{ Html.RenderAction("Customers", "ManageDDLs", new { area = "Shared" }); }[ChildActionOnly] public ActionResult Customers() { List<ddlOptions> viewModel = new List<ddlOptions>(); viewModel = _manageDDLsAppServ.GetCustomersDDLViewModel(_currentCompanyId).ToList(); ViewBag.ControlId = "customerIdFilter"; return PartialView("_ddlOptionsAutoComplete", viewModel); }