1

を使用すると、(モデルで指定されているように) Razor MVC 4.0 ' ' の必須フィールドを持つビューがあります。Name私は持っていますKendo Grid / EditMode InLine / Server bound Data source(下記参照)

@(Html.Kendo().Grid(モデル)

  .Name("Grid") 

  .Events(e => e.Edit("gridChange")) 

  .Columns(columns =>
  {
      columns.Bound(p => p.Id).Hidden();   //Create a column bound to the "ProductID" property
      columns.Bound(p => p.Name).Width(120); //Create a column bound to the "ProductName" property
      columns.Bound(p => p.SortValue).Width(80).EditorTemplateName("SortNumericTextBox");   //Create a column bound to the "UnitPrice" property
      columns.Bound(p => p.Active).Width(100);//Create a column bound to the "UnitsInStock" property

      columns.Command(command => command.Edit()).Width(100);
  })
 .ToolBar(toolbar => toolbar.Create())
 .Editable(editable => editable.Mode(GridEditMode.InLine))
 .DataSource(dataSource => dataSource
        .Server()
        .Model(model =>
        {
            model.Id(p => p.Id);
            model.Field(p => p.Name ).Editable(true);
            model.Field(p => p.SortValue);
            model.Field(p => p.Active);

        })

     // Configure CRUD -->
        .Create(create => create.Action("Create", "MonitorType"))
        .Read(read => read.Action("Index", "MonitorType"))
        .Update(update => update.Action("Edit", "MonitorType"))         
        .PageSize(5)

       )
 .Pageable() //Enable paging

 )

コントローラー (HTTP) で編集および作成しますModelState.IsValid(名前が空白の場合は false)。更新は行われません。グリッドに戻ります。

    [HttpPost]
    public ActionResult Create(MonitorType monitortype)
    {
        if (ModelState.IsValid)
        {
            unitOfWork.MonitorTypeRepository.Insert(monitortype);
            unitOfWork.Save();
            return RedirectToAction("Index");
        }

        //GridRouteValues() is an extension method which returns the
        //route values defining the grid state - current page, sort expression, filter etc.
        RouteValueDictionary routeValues = this.GridRouteValues();
        return RedirectToAction("Index", routeValues);
    }

しかし - 検証メッセージは「Not」表示されます。

検証メッセージをどのように表示しますか?

4

1 に答える 1

-1

私が見る限り、2つのことが必要です。

まず、DataSource(例.ajax().events(events => events.Error("error_handler")))でエラーハンドライベントを割り当てます。

次に、エラー ハンドラー スクリプトを追加します (このコードはほぼすべての Kendo UI デモで使用できます)。

 function error_handler(e, status) {
    if (e.errors) {
        var message = "The following are errors:\n";
        $.each(e.errors, function (key, value) {
            if ('errors' in value) {
                $.each(value.errors, function () {
                    message += this + "\n";
                });
            }
        });
        alert(message);
    }
}

最後に、ModelStateエラーを表示できるように、コントローラーは をパラメーターとして返す必要があります。グリッドのデモを見ると、MVC コントローラー コードに次のように表示されます。

return Json(results.ToDataSourceResult(request, ModelState));
于 2013-04-03T21:43:54.443 に答える