Telerik 验证错误未显示在网格中

Telerik 验证错误未显示在网格中,telerik,telerik-grid,telerik-mvc,Telerik,Telerik Grid,Telerik Mvc,我有一个MVC3RazorTelerik网格。单击编辑按钮的更新时,将执行适当的控制器并执行TryUpdateModel语句 我故意写了一些我知道会导致错误的文字。TryUpdateModel返回false(在这种情况下是应该的),然后执行returnview();声明 然而,我得到一个模态对话框,上面写着“请求的URL返回了一个500错误”。如果单击模态对话框并查看网格,则不会显示验证消息 如果我使用的是带有输入框的Telerik网格,而不是,那么从驻留在模型中的DataAnnotation中

我有一个MVC3RazorTelerik网格。单击编辑按钮的更新时,将执行适当的控制器并执行TryUpdateModel语句

我故意写了一些我知道会导致错误的文字。TryUpdateModel返回false(在这种情况下是应该的),然后执行returnview();声明

然而,我得到一个模态对话框,上面写着“请求的URL返回了一个500错误”。如果单击模态对话框并查看网格,则不会显示验证消息

如果我使用的是带有输入框的Telerik网格,而不是,那么从驻留在模型中的DataAnnotation中可以看到验证消息

我做错了什么?

以下是我的看法:

@model Telerik.Web.Mvc.GridModel<YeagerTech.YeagerTechWcfService.Customer>
@{
    ViewBag.Title = "Customer Index";
}
<h2>
    Customer Index</h2>
@(  Html.Telerik().Grid<YeagerTech.YeagerTechWcfService.Customer>(Model.Data)
      .Name("Customers")
            .DataKeys(dataKeys => dataKeys.Add(o => o.CustomerID)
                                            .RouteKey("CustomerID"))
                .ToolBar(commands => commands.Insert().ButtonType(GridButtonType.Text).ImageHtmlAttributes(new { style = "margin-left:0" }))
      .Columns(columns =>
            {
                columns.Bound(o => o.CustomerID).Hidden(true);
                columns.Command(commands =>
                {
                    commands.Edit().ButtonType(GridButtonType.Text);
                }).Width(200).Title("Command");
                columns.Bound(o => o.Email).Width(200);
                columns.Bound(o => o.Company).Width(200);
                columns.Bound(o => o.FirstName).Width(100).Title("FName");
                columns.Bound(o => o.LastName).Width(100).Title("LName");
                columns.Bound(o => o.Address1).Width(200).Title("Addr1");
                columns.Bound(o => o.Address2).Width(100).Title("Addr2");
                columns.Bound(o => o.City).Width(100);
                columns.Bound(o => o.State).Width(40).Title("ST");
                columns.Bound(o => o.Zip).Width(60);
                //columns.Bound(o => o.HomePhone).Width(120);
                //columns.Bound(o => o.CellPhone).Width(120);
                //columns.Bound(o => o.Website).Width(100);
                //columns.Bound(o => o.IMAddress).Width(100);
                //columns.Bound(o => o.CreatedDate).Format("{0:MM/dd/yyyy}").ReadOnly(true).Width(120);
                //columns.Bound(o => o.UpdatedDate).Format("{0:MM/dd/yyyy}").ReadOnly(true).Width(120);
            }).DataBinding(dataBinding =>
                dataBinding.Ajax()
                        .Insert("_InsertAjaxEditing", "Customer")
                        .Update("_SaveAjaxEditing", "Customer"))
    .Editable(editing => editing.Mode(GridEditMode.InLine))
    .Pageable()
    .Sortable()
    .Scrollable()
 )

我发现验证没有显示,原因有二:1)如果您使用EF,并且使用EF通过DBContext生成的POCO类(包含对其他实体的引用属性),那么模型不喜欢MVC中的缺陷。2) 如果您在数据层的N层体系结构中使用模型类,MVC也不会识别验证。唯一的情况是在表示层(在Models文件夹中)上有一个模型,而类中没有任何引用属性。这需要尽快在MVC中修复。
[HttpPost]
        [GridAction]
        public ActionResult _SaveAjaxEditing(YeagerTechWcfService.Customer customer)
        {
            CustomerValidate custValidate = new CustomerValidate();

            custValidate.CustomerID = customer.CustomerID;
            custValidate.Email = customer.Email;
            custValidate.Company = customer.Company;
            custValidate.FirstName = customer.FirstName;
            custValidate.LastName = customer.LastName;
            custValidate.Address1 = customer.Address1;
            custValidate.Address2 = customer.Address2;
            custValidate.City = customer.City;
            custValidate.State = customer.State;
            custValidate.Zip = customer.Zip;
            custValidate.HomePhone = customer.HomePhone;
            custValidate.CellPhone = customer.CellPhone;
            custValidate.Website = customer.Website;
            custValidate.IMAddress = customer.IMAddress;

            if (TryUpdateModel(custValidate))
            {
                try
                {
                    db.EditCustomer(customer);
                    TempData["ErrCode"] = "Customer successfully updated.";
                    return RedirectToAction("Index", "Home");
                }
                catch (Exception ex)
                {
                    TempData["ErrCode"] = "CustErr";
                    ViewBag.Error = ex.Message;
                    return View();
                }

            }
            else
                return View();
        }