使用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
(名称为空时为假)。没有更新发生。返回网格。
[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);
}
但是 - 验证消息是“不”显示。
您如何显示验证消息?