我怎样才能获得的WebGrid所选行到隐参量。
我使用下面的代码。
@{
var grid = new WebGrid(@ViewBag.ImageFiles, canPage: false, rowsPerPage: 5, selectionFieldName: "SelectedRow", ajaxUpdateContainerId: "gridImages");
}
<div id="gridContent">
@grid.GetHtml(tableStyle: "webGrid",
htmlAttributes: new { id = "gridImages" },
headerStyle: "header",
displayHeader: true,
alternatingRowStyle: "alt",
selectedRowStyle: "select",
columns: grid.Columns(
grid.Column("Select", format: (item) => item.GetSelectLink("Select")),
grid.Column("File", "Image")))
</div>
<input type="button" value="Submit" onclick="javascript getSelectedRow();"/>
@{
System.Dynamic.ExpandoObject expobject = null;
if (grid.HasSelection)
{
expobject = (System.Dynamic.ExpandoObject)grid.SelectedRow.Value;
<input type="hidden" id="hdnSelectedRow" name="hdnSelectedRow" value="@(expobject == null ? "" : expobject.FirstOrDefault().Value.ToString())" />
}
}
这里我绑定的DataTable从下面的代码的WebGrid
foreach (DataRow row in imageFiles.Rows)
{
var obj = (IDictionary<string, object>)new ExpandoObject();
foreach (DataColumn col in imageFiles.Columns)
{
obj.Add(col.ColumnName, row[col.ColumnName]);
}
result.Add(obj);
}
ViewBag.ImageFiles = result;
当我点击提交按钮,我没有得到隐藏的变量和值在JavaScript。