0

I have 2 WebGrid. I want to use the property SelectedRow. in the first WebGrid works well, but the second not.

This is the main view (WebGrid 1), here called a partial view that contains the second 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"] });
   }

}

This is a partial view of the second WebGrid (WebGrid 2). The WebGrid 2 contains records, but Why grid2.SelectedRow ["IdConsultation"] is 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");
  }

blessings

kalu
  • 337
  • 2
  • 9
  • 19

2 Answers2

0

grid2.SelectedRow ["IdConsultation"] is NULL because nothing is selected. You should set the first row selected by default if you want so.

nathanchere
  • 8,008
  • 15
  • 65
  • 86
Venu
  • 184
  • 3
  • 14
0

im currently using the selection by Javascript with the following JS code:

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

Hope this help!

IGeoorge
  • 140
  • 1
  • 8