假设我的webgrid代码看起来像
假设这是我的webgrid代码
@model HelloWorldMvcApp.MainViewModel
@{
Layout = null;
}
@{
WebGrid grid = new WebGrid(null);
grid.Bind(Model.Students);
}
@grid.GetHtml(
tableStyle: "webgrid-table",
headerStyle: "webgrid-header",
footerStyle: "webgrid-footer",
alternatingRowStyle: "webgrid-alternating-row",
selectedRowStyle: "webgrid-selected-row",
rowStyle: "webgrid-row-style",
mode: WebGridPagerModes.All,
firstText: "<<",
previousText: "<",
nextText: ">",
lastText: ">>",
numericLinksCount: 5,
columns:
grid.Columns
(
grid.Column(columnName: "ID", header: "ID", format: @<text>@item.ID</text>,style:"SmallCols"),
grid.Column(columnName: "FirstName", header: "First Name", format: @<text><input type="text" id="txtFirstName" value="@item.Name" class="edit-mode" /></text>,style:"NameColWidth" ),
//grid.Column(columnName: "StateName", header: "State Name", format: @<text>@Html.DropDownListFor(x => x.SelectedState, new SelectList(Model.Students[1].States, "ID", "Name", Model.SelectedState = item.StateID), "-- Select States--", new { id = "cboState", @class = "edit-mode" })</text>,style:"NameColWidth"),
grid.Column(columnName: "StateName", header: "State Name", format: @<text>@Html.DropDownListFor(x => x.SelectedState, new SelectList(Model.Students.SelectMany(x => x.States).Where(x => x.ID == item.StateID), "ID", "Name", Model.SelectedState = item.StateID), "-- Select States--", new { id = "cboState", @class = "edit-mode" })</text>,style:"NameColWidth"),
grid.Column(columnName: "CityName", header: "City Name", format: @<text>@Html.DropDownListFor(x => x.SelectedCity, new SelectList(Model.Students.SelectMany(x => x.Cities).Where(x => x.StateID == item.StateID), "ID", "Name", Model.SelectedCity = item.CityID), "-- Select City--", new { id = "cboCity", @class = "edit-mode" })
</text>,style:"NameColWidth")
))
现在告诉我如何为每个文本框和下拉列表添加@Html.ValidationMessageFor
?
我的完整工作代码https://dotnetfiddle.net/GoJeBE
请与代码示例讨论。感谢