【问题标题】:webgrid selected row MVC 3webgrid选择行MVC 3
【发布时间】:2012-08-04 16:01:12
【问题描述】:

我有 2 个 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"] 为 NULL?

**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");
  }

祝福

【问题讨论】:

  • 请帮忙,我还没有找到解决办法

标签: asp.net-mvc-3 webgrid


【解决方案1】:

grid2.SelectedRow ["IdConsultation"] 为 NULL,因为未选择任何内容。如果需要,您应该设置默认选择的第一行。

【讨论】:

    【解决方案2】:

    我目前正在使用带有以下 JS 代码的 Javascript 选择:

        $(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;
        });
    

    希望对您有所帮助!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-09-11
      • 2011-06-14
      • 2012-07-02
      • 2012-06-23
      • 1970-01-01
      • 2012-05-13
      • 2011-08-13
      • 2012-04-30
      相关资源
      最近更新 更多