如何将 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 中获得隐藏变量和值。