Kendo MVC Wrappers客户端验证

时间:2012-12-27 14:07:44

标签: asp.net-mvc telerik data-annotations kendo-ui telerik-mvc

我正在使用Kendo UI Server Side Wrappers创建一个网格来管理(CRUD)我们系统中的消息列表。该模型非常简单,只需要消息为150个字符或更少。为了强制执行消息长度,我在模型中使用了以下数据注释:

[StringLength(150, ErrorMessage = "Message exceeded the maximum length allowed.  Please ensure you message is no longer than 150 characters")]        

这是我的网格的样子:

@model OperatorMessageListModel

@{
    TransactionStatusType status = Model.TransactionStatus;
    ViewBag.Title = String.Format("{0} Transaction Operator Messages", status);
    string header = string.Format("{0} Transaction Messages", status);
    string messagesTableId = string.Format("{0}TransactionOperatorMessagesGrid", status);
}

<h2>@header</h2>

@(Html.Kendo().Grid(Model.OperatorMessages)
      .Name(messagesTableId)
      .TableHtmlAttributes(new { style = "width: 50% height:75%" })
      .Columns(columns =>
                   {

                       columns.Bound(m => m.Message).Title("");
                       columns.Bound(m => m.Index).Hidden(true);
                       if (!Model.IsInherited) //only edit if you own the list and there's anyhting to edit
                       {
                           columns.Command(cmd =>
                                               {
                                                   cmd.Edit().UpdateText("Save");
                                                   cmd.Destroy();
                                               }).Width("20%");

                       }
                   })
     .Pageable()
     .Scrollable(s => s.Enabled(false))
     .ToolBar(cmd =>
                  {

                      if (!Model.IsInherited) //you can add messages to the lists that you own
                      {
                          cmd.Create().Text("Add new message");
                      }

                      if (!Model.OwnedByRoot && Model.OperatorMessages.Any()) //if the root owns this it can't override or inherit its own list.
                      {
                          var actionName = Model.IsInherited ? "OverrideTrasactionMessageList" : "InheritTrasactionMessageList";
                          cmd.Custom().Text(Model.OverrideOrInheritButtonText).Action(actionName, "OperatorMessage", new { Model.OrgId, Model.TransactionStatus });
                      }
                  }
           )

     .Editable(editable => editable.Mode(GridEditMode.InLine))
     .DataSource(ds => ds
        .Server()
        .Model(model => model.Id(m => m.Index))
        .Create(c => c.Action("CreateTransactionMessage", "OperatorMessage", new { @Model.OrgId, @Model.TransactionStatus }))
        .Read(c => c.Action("List", "OperatorMessage", new { @Model.OrgId, @Model.TransactionStatus }))
        .Update(c => c.Action("EditTransactionMessage", "OperatorMessage"))
        .Destroy(c => c.Action("DeleteTrasactionMessage", "OperatorMessage"))

     )
)

这是控制器代码:

[HttpPost]
public ActionResult CreateTransactionMessage([DataSourceRequest] DataSourceRequest request,
                                                 OperatorMessageModel newMessage, string OrgId,
                                                 string TransactionStatus)
{

    _transactionOperatorMessageService.AddOperatorMessage(OrgId, TransactionStatus, newMessage,
                                                          CurrentUser.Name());
    return RedirectToAction("List", new {OrgId, TransactionStatus});
}

当用户输入超过150个字符的消息时,我希望验证消息显示给用户。此外,表格不会回发给控制器。一切都在Chrome和Firefox中完成。但是,在IE8中会显示消息,但表单仍会发回控制器。有没有人见过这个?

0 个答案:

没有答案