I researched and cannot find the answer that I can use to pass the ID value back to the controller when the user clicks on the SELECT cell of the WebGrid row using mvc4 asp.net vs2012.
My WebGrid looks like this (partially):
@{
ViewBag.Title = "Customers";
WebGrid grid = new WebGrid(source: Model.oCustItems, canPage: false, rowsPerPage: 50,
selectionFieldName: "selectedRow",
ajaxUpdateContainerId: "grid",
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>
Here is what I discovered.
- The value "selectedRow" is included in the controller.
- The value "UID_CUSTOMER" is always entered as NULL.
- (grid.hasSelection) fires AFTER reprocessing after returning from the controller.
I need to get the value "UID_CUSTOMER" (located in the first column (hidden) so that it is a valid value when acting on the controller action. But I can not find a way to get and send the value for the controller declared as:
[HttpGet]
public ActionResult Index(Int32? UID_CUSTOMER, Int32? selectedRow)
{
.
jQuery javascript, mvc ( , - .net), , , ... ... John