2013-02-12 2 views
1

사용 Razor MVC 4.0 필자는 모델에 지정된대로 'Name'의 필수 필드가있는보기가 있습니다. 나는이 Kendo Grid/EditMode InLine/Server bound Data source @KENDO UI 편집 가능한 InLine Grid Server 바인딩 유효성 검사 메시지가 표시되지 않음

(아래 참조)이 (Html.Kendo(). 그리드 (모델)

.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 (대한 확인을 만들기 그것은 거짓 ... 이름이) 비어있는 경우 없음 업데이트

[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); 
    } 

그리드에 반환을 발생하지 그러나 - 확인 메시지가 표시 '하지'입니다

.

어떻게 유효성 확인 메시지를 표시합니까?

답변

-1

내가 볼 수있는 한 두 가지가 필요합니다.

먼저 오류 처리기 이벤트를 DataSource (예 : .ajax().events(events => events.Error("error_handler")))에 할당합니다.

둘째, (이 코드는 거의 모든 검도 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 controller code에서 다음을 볼 수 있습니다 :

return Json(results.ToDataSourceResult(request, ModelState)); 
+0

문제는 오류 이벤트를 사용할 수없는 경우에 서버 바인딩 그리드에 관한 것이다. – msulis