2012-08-07 94 views
0

我有2個WebGrid。我想要使​​用屬性SelectedRow。在第一個WebGrid中運行良好,但第二個沒有。webgrid選擇行MVC 3

這是主視圖(的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"); 
    } 

祝福

+0

請幫忙,我還沒找到解決辦法 – kalu 2012-08-13 13:55:44

回答

0

grid2.SelectedRow ["IdConsultation"]爲NULL。如果需要,您應該設置默認選擇的第一行。

0

IM目前使用選擇通過的Javascript下面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; 
    }); 

希望這有助於!