我已经研究过,当用户使用mvc4 asp.net vs2012点击WebGrid行的SELECT单元格时,我无法找到可用于将ID值传递回控制器的答案。
我的WebGrid在(部分)视图中看起来像这样:
@{
ViewBag.Title = "Customers";
WebGrid grid = new WebGrid(source: Model.oCustItems, canPage: false, rowsPerPage: 50,
selectionFieldName: "selectedRow",
ajaxUpdateContainerId: "grid", // pointer to the grid-control as defined with this new WebGrid call.
sortFieldName: "Active", defaultSort: "Active");
}
<div id="divForm" class="webgrid_div_container">
@using (Html.BeginForm("GridRowClicked", "MainPage", FormMethod.Post))
{
@Html.Hidden("oValue", 1)
grid.SelectedIndex=ViewBag.SelectedIndex;
@grid.GetHtml(
...styling here... ,
columns: grid.Columns(
grid.Column(null,null, format: @<input type="hidden" name="hidUID_CUSTOMER" value="@item.UID_CUSTOMER"/>),
grid.Column(columnName: "CustomerID", format: (item) => item.GetSelectLink(item.CustomerID.ToString()), header: "Select", style: "webgrid-select"),
grid.Column(columnName: "CompanyName", header: "Company Name"),
grid.Column(columnName: null, header: "Inspection", format: @<text>06/28/2015</text>),
grid.Column(columnName: "Active", header: "Active?", format: @<text><input type="checkbox" checked="@item.Active" disabled="disabled" /></text>)
),
htmlAttributes: new { id = "MainTable" }
)
if (grid.HasSelection)
{
<input type="hidden" id="UID_CUSTOMER" name="UID_CUSTOMER" value="@grid.SelectedRow["UID_CUSTOMER"]"/>
@Html.Hidden("UID_CUSTOMER", grid.SelectedRow["UID_CUSTOMER"])
}
}
</div>
这是我发现的。
我需要的是获得&#39; UID_CUSTOMER&#39; value(位于第一列(隐藏)中,以便在对控制器操作执行操作时它是一个有效值。但我似乎无法找到获取并将值发送到声明为的控制器的方法:
[HttpGet]
public ActionResult Index(Int32? UID_CUSTOMER, Int32? selectedRow)
{
任何帮助将不胜感激。 我有新手级jQuery和javascript技能,以及初学者mvc技能(主要是网络形式.net技能)所以请相应回复...谢谢...... John