Kendo Grid Pop-up Validation

2 posts, 0 answers
  1. Chuck
    Chuck avatar
    10 posts
    Member since:
    May 2011

    Posted 15 Mar 2016 Link to this post


    I've been running into a problem when trying to validate the pop-ups from a grid edit.

    When I have everything set up as in the code below, errors from the controller are returned as a string on a new page, rather than to the ValidationSummary or ValidationMessage Tags.

    Here is the PartialView used as a template for the Pop-up editor

    @model CopyOrder
    <script src="~/Scripts/jquery.validate.unobtrusive.js"></script>
    <script src="~/Scripts/jquery.validate.unobtrusive.min.js"></script>
    <div class="EditorContainer">
        <div id="OrderEditorSubHeader">Order <b>Information</b></div>
    @using (Html.BeginForm("OrderCopy", "OrderManagement")){
        <div class="form-group">
            @Html.Label("Copy Order ID")
            .Placeholder("Please Select")
            .DataSource(dataSource => dataSource.Read(read => read.Url("/OrderManagement/OrderID_Select")))
            .HtmlAttributes(new { @class = "form-control" }))
            @Html.ValidationMessageFor(m => m.CopyOrderID)
        <div class="form-group">
            @Html.Label("Copy To Customer")
            .Placeholder("Please Select")
            .DataSource(dataSource =>
                dataSource.Read(read =>
                        read.Action("AvailableCustomers_Select", "OrderManagement")
            .HtmlAttributes(new { @class = "form-control" }))      
            @Html.ValidationMessageFor(m => m.CopyCustomerID)    
        <input id="submitbtn" type="submit" value="Save" />

    Here is the Controller code

            public ActionResult OrderCopy([DataSourceRequest] DataSourceRequest request, Ops.Models.CopyOrder Copy)
                var db = new Ops.Models.Ops_Entities();
                if (ModelState.IsValid)
                        //A bunch of Linq Queries here

                        //One of them causes a NullReference Exception

                        return RedirectToAction("Orders");
                    catch (NullReferenceException)

                                                         //Code reaches this point when I trigger the error in question

                                                         //Problem is that when it is returned, a new page is  opened just displaying the error message as a string

                        ModelState.AddModelError(String.Empty, "Invalid Selection");
                        var failmodel2 = (new List<Ops.Models.CopyOrder> { Copy }).ToList().ToDataSourceResult(request, ModelState);
                        return Json(failmodel2, JsonRequestBehavior.AllowGet);
                var failmodel = new List<Ops.Models.CopyOrder>();
                return Json(failmodel.ToDataSourceResult(request, ModelState));

    and my kendo grid 

                .Columns(columns =>
                    columns.Bound(p => p.SchoolYear)
                    columns.Bound(p => p.Company)
                        .Title("School Name")
                        .ClientTemplate("<span><a href='/CustomerManagement/SchoolInfo?CustomerID=#=CustomerID#'>#=Company#</a></span>");
                    columns.Bound(p => p.MasterOrderID)
                        .Title("Order ID");
                    columns.Bound(p => p.GroupName);
                    columns.Bound(p => p.Type);
                    columns.Bound(p => p.Program);
                    columns.Bound(p => p.Status)
                    columns.Bound(p => p.AddUser);
                    columns.Bound(p => p.SalesTerritory)
                .Editable(editable => editable.Mode(GridEditMode.PopUp).TemplateName("OrderGroupEdit"))
                .ToolBar(toolBar =>
                    toolBar.Create().Text("Add Order");
                    toolBar.Custom().Text("Copy Order").HtmlAttributes(new { id = "openCopyWindow" });
                    toolBar.Custom().Text("Add Service Item").HtmlAttributes(new { id = "openServiceItemWindow" });
                    toolBar.Custom().Text("Get Job Master").HtmlAttributes(new { id = "openJobMastWindow" });
                .Pageable(o =>
                    o.PageSizes(new[] { 11, 20, 50, 100, 1000 });
                .Filterable(f =>
                    f.Operators(o =>
                        o.ForString(d => d
                            .IsEqualTo("Equal To")
                .Events(e => e.DataBound("onDataBound"))
                .DataSource(dataSource => dataSource
                    .Model(model => model.Id(m => m.MasterOrderID))
                    .Read(read => read.Action("OrderSearch", "OrderManagement"))
                    .Create(create => create.Action("OrderCreate", "OrderManagement"))

        .Title("Copy Order")
        .LoadContentFrom("CopyOrder", "OrderManagement")
        //.Events(e => e.Close("ManualWindow_close"))

    and the js opening the window

    $(document).ready(function () {
            $("#openCopyWindow").click(function (e) {
                var window = $("#window").data("kendoWindow");



  2. Georgi Krustev
    Georgi Krustev avatar
    3747 posts

    Posted 18 Mar 2016 Link to this post

    Hello Chuck,

    In general, the Grid widget uses Ajax requests to communicate with the server when an item is updated/created.

    I noticed that you are placing the popup editor form inside a regular HTML Form element. This definitely will post the whole page. What I would suggest you use an editor form that is not put in HTML Form element. You can find a detailed information how to do that here:
    Georgi Krustev
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Back to Top