我有一个带有下拉列表的 webgrid 并 onchange 它回发页面。我正在尝试获取下拉列表的选定值。
以下是我的控制器。
public ViewResult Index()
{
//var albums = db.Albums.Include(a => a.Artist).Include(a => a.Genre);
var model = new AlbumActionModel { Actions = new[] { new SelectListItem { Text = "Accept", Value = "Accept" }, new SelectListItem { Text = "Deny", Value = "Deny" } }, Albums = db.Albums.Include(a => a.Artist).Include(a => a.Genre) };
return View(model);
}
以下是我的观点。
<div>
@{
WebGrid grid = new WebGrid(Model.Albums, defaultSort: "Title", selectionFieldName: "SelectedRow");
}
@using (Html.BeginForm("Index", "Album", FormMethod.Post, new { id = "TheForm" }))
{
@grid.GetHtml(columns: grid.Columns(grid.Column("Edit",
format: @<text> @Html.ActionLink("Edit", "Edit", new { id = item.AlbumId })></text>),
grid.Column("AlbumId"),
grid.Column("Title"),
grid.Column("Action",
format:
@<span>
@{var index = item.AlbumId.ToString();}
@Html.DropDownList("Actions" +((string)index), Model.Actions, "--Select One--", new { onchange = "this.form.submit();" })
</span>),
grid.Column("Delete",
format: @<text> @Html.ActionLink("Delete", "Delete", new { id = item.AlbumId })></text>)))
</div>
提前致谢。