0
我从过去几天开始使用网格。一切都非常方便与webgrid像显示列不同的数据类型,如文本框,标签,下拉等,但如何保存数据或更新数据。Webgrid下拉列表保存或更新
我尝试使用操作链接并提交按钮,但没有人为我工作。他们没有获取我的控制器中修改的下拉数据。操作链接能够获取用户标识,但无法获得更改的下拉值。
下面是代码:
查看
WebGridColumn colLocation = null;
foreach (var col in Model)
{
colLocation = new WebGridColumn()
{
Header = "Locations",
Format = (item) => @Html.DropDownList("LocationId", @col.LocationItems.Select(l => new SelectListItem
{
Text = l.Text,
Value = l.Value,
Selected = ((WebGridRow)item)["LocationId"].ToString() == l.Value
}
)
)
};
colSave = new WebGridColumn()
{
Header = "Save User",
Format = (item) => Html.ActionLink("Save", "Save", "UsersList", new { userId = item.UserId, locationId = item.LocationId }, new { @class = "btn btn-default" }),
CanSort = true
};
}
columns.Add(colLocation);
columns.Add(colSave);
@grid.GetHtml(tableStyle: "webgrid",
headerStyle: "header",
selectedRowStyle: "select",
alternatingRowStyle: "alt",
columns: columns
)
控制器
public ActionResult Save(int userId, int locationId)
{
var user = Utility.SetUserDetails(userId, locationId);
return RedirectToAction("UsersList");
}