我有两个WebGrid。我想使用属性SelectedRow。第一个WebGrid运行得很好,但第二个就不行了。
这是主视图(WebGrid 1),这里称为包含第二个WebGrid的分部视图:
@model IEnumerable<RolesMVC3.Models.ESTUDENT>
@{
ViewBag.Title = "Index";
WebGrid grid = new WebGrid(Model);
}
<h2>Index</h2>
@using (Html.BeginForm())
{
@grid.GetHtml(fillEmptyRows: false,
alternatingRowStyle: "alternate",
headerStyle: "header",
tableStyle: "table",
selectedRowStyle: "selected",
mode: WebGridPagerModes.All,
columns: new[] {
grid.Column("IdEstudent", header: "ID"),
grid.Column("NameEstudent", header: "Name"),
grid.Column("LastNameEstudeNT", header: "Last Name"),
grid.Column( "", header: " ",format:@<text>@item.GetSelectLink("SELECT")</text>)
})
if (grid.HasSelection)
{
Html.RenderAction("Process", "Pass", new { id = grid.SelectedRow["IdEstudent"] });
}
}这是第二个WebGrid (WebGrid 2)的局部视图。WebGrid 2包含记录,但为什么grid2.SelectedRow "IdConsultation“为空?
**Process.cshtml:**
@model IEnumerable<RolesMVC3.Areas.Manager.Models.ConsViewModel>
@{
WebGrid grid2 = new WebGrid(Model);
}
@grid2.GetHtml( fillEmptyRows: false,
alternatingRowStyle: "alternate",
headerStyle: "header",
tableStyle : "table",
selectedRowStyle: "selected",
mode: WebGridPagerModes.All,
columns: new [] {
grid2.Column("IdConsultation", header: "Consultation"),
grid2.Column("Idregister", header: "Register"),
grid2.Column( "", header: " ",format:@<text>@item.GetSelectLink("SELECT")</text>)
})
@if (grid2.HasSelection)
{
<input type="hidden" id="Consultation" name="Consultation" value="@grid2.SelectedRow["IdConsultation"]"/>
Html.RenderAction("EstudianiatesCJ1", "Sustitucion");
}祝福
发布于 2013-10-08 11:52:23
grid2.SelectedRow ["IdConsultation"]为NULL,因为未选择任何内容。如果需要,您应该设置默认选中的第一行。
发布于 2014-01-21 01:44:54
我目前正在使用Javascript的selection和以下JS代码:
$(document).on('click', '#selectBtn', function () {
var tr = $(this).closest('tr');
tr.addClass('info').siblings().removeClass('info');
/*Here you can send selection to controller */
return false;
});希望这对你有所帮助!
https://stackoverflow.com/questions/11849346
复制相似问题