Dishant Patel

Dishant Patel

  • NA
  • 2
  • 2.3k

nested webgrid data call in controller in MVC 4

Apr 1 2016 8:44 AM
Hii..
I want values which are bind in nested webgrid in controller. On button click i want nested webgrid  data.
 
@grid.GetHtml(
mode: WebGridPagerModes.All,
htmlAttributes: new { id = "gridT", @class = "dBody tableRowDivider1", cellpadding = "0", cellspacing = "0", width = "100%", style = "border-top:solid 1px" },
columns: grid.Columns(
// grid.Column(header: "Action", format: (a) => a.role.roleid),
grid.Column(header: "", format: @<text>
<a href="/Role/[email protected]" id="[email protected]" class="edit"><img src="~/Images/icon_edit.gif" /></a>
<a href="/Role/[email protected]" id="[email protected]" class="delete"><img src="~/Images/icon_delete_over.gif" /></a></text>,style:"born"),
grid.Column("Role.rolename", "Role Name"),
grid.Column("Role.Rolecode", "Role Code"),
grid.Column("Role.Description", "Description"),
grid.Column("", "", format: @<text><table>
<tr><td><span class="spantab" id="1">Role Page</span></td><td><span class="spantab" id="2">Role Users</span></td><td><span class="spantab" id="3">Users Role</span></td></tr>
<tr>
<td style="border:none">
<div tabindex="0" class="onclick-menu">
ACTIONS <ul class="onclick-menu-content" style="width:150px">
<div>
<div style="float:right; padding:5px 0px 10px 0px;"> <a href=""><img src="~/images/closeButtonOver.gif" /></a> </div> <div class="clear"></div> <div>
<div style="float:left; padding:5px 5px 10px 0px;"> <a href="#popup5"><img src="images/ButtonBarNew.gif" /></a> </div>
<div style="float:left; padding:5px 0px 10px 0px;">
<a id="btnsave" href=""><img src="images/ButtonBarSaveOver.gif" /></a>
</div> <div style="float:left; padding:5px 0px 10px 5px;"> <a href=""><img src="images/ButtonBarRefreshOver.gif" /></a> </div>
</div>
</div>
</ul>
</div>
</td>
<td style="border:none"><div tabindex="0" class="onclick-menu">FILTERS <ul class="onclick-menu-content" style="width:300px"> <div><div style="float:right; padding:5px 0px 10px 0px;"><a href=""><img src="images/closeButtonOver.gif" /></a></div><div class="clear"></div><div> <div style="float:left; padding:0 10px 0 0;">Page Name</div><div class="butc"><button>All</button></div></div><div class="clear"></div><div><div style="float:left; padding:0 10px 0 0;">Page</div><div style="float:left; padding:0 10px 0 0;"> <select name="" id="" class="Filter_Input"> <option selected="selected" value="--ANY--">Show All</option> <option value="--Included--">Show Included</option> </select></div><div class="butc"><button>Go</button></div> <div style="float:left"><a href=""><img src="images/ButtonBarResetOver.gif" /></a></div></div></div> </ul></div></td>
<td style="border:none"><input type="text" name="serach" class="Search_InputHint" /></td>
</tr>
<tr style="display:none; "><td style="border:none"><div tabindex="0" class="onclick-menu">ACTIONS <ul class="onclick-menu-content" style="width:150px"> <div> <div style="float:right; padding:5px 0px 10px 0px;"> <a href=""><img src="~/images/closeButtonOver.gif" /></a> </div> <div class="clear"></div> <div> <div style="float:left; padding:5px 5px 10px 0px;"> <a href=""><img src="images/ButtonBarNew.gif" /></a> </div> <div style="float:left; padding:5px 0px 10px 0px;"> <a href=""><img src="images/ButtonBarSaveOver.gif" /></a> </div> <div style="float:left; padding:5px 0px 10px 5px;"> <a href=""><img src="images/ButtonBarRefreshOver.gif" /></a> </div> </div> </div></ul></div></td><td style="border:none"><div tabindex="0" class="onclick-menu">FILTERS <ul class="onclick-menu-content" style="width:300px"> <div><div style="float:right; padding:5px 0px 10px 0px;"><a href=""><img src="images/closeButtonOver.gif" /></a></div><div class="clear"></div><div> <div style="float:left; padding:0 10px 0 0;">Page Name</div><div class="butc"><button>All</button></div></div><div class="clear"></div><div><div style="float:left; padding:0 10px 0 0;">Page</div><div style="float:left; padding:0 10px 0 0;"> <select name="" id="" class="Filter_Input"> <option selected="selected" value="--ANY--">Show All</option> <option value="--Included--">Show Included</option> </select></div><div class="butc"><button>Go</button></div> <div style="float:left"><a href=""><img src="images/ButtonBarResetOver.gif" /></a></div></div></div> </ul></div></td><td style="border:none"><input type="text" name="serach" class="Search_InputHint" /></td></tr>
</table></text>),
grid.Column(format: (itemp) =>
{
WebGrid subGrid1 = new WebGrid(source: itemp.page, canPage: true, pageFieldName: "Pagename" + itemp.role.roleid, rowsPerPage: 10);
return subGrid1.GetHtml(
mode: WebGridPagerModes.Numeric,
htmlAttributes: new { id = "subT", @class = "tableRowDivider", style = "border-top:solid 1px" },
columns: subGrid1.Columns(
@*subGrid1.Column(header: "", format: @<text>
<tr style=" border:none;"><td style="border:none;">test</td></tr></text>),*@
subGrid1.Column(header: "", format: @<text>
<input id="select" name="select" type="checkbox" @(@item.ischeck ? "checked='checked'" : "") value="" />
@*<label id="lblpageid" style="display:block">@item.role.roleid</label>*@
</text> , style: "text-center checkbox-width SmallCols"),
// subGrid1.Column(header: "testing", format: @<text>@if (itemp.Page_Role.pageid == @item.pageid) {@(itemp.Page.Pageid);}</text>),
subGrid1.Column("Pagename", "Pagename"),
subGrid1.Column("PageID", style: "gridhide", header: "")
//subGrid1.Column(format:@<input type="hidden" id="pageid" value="@itemp."/>)
)
);
}),
grid.Column(format: (item1) =>
{
WebGrid subGrid = new WebGrid(source: item1.Users, canPage: true, pageFieldName: "firstname" + item1.role.roleid, rowsPerPage: 10);
return subGrid.GetHtml(
htmlAttributes: new { id = "subT", @class = "tableRowDivider", style = "display:none;border-top:solid 1px" },
columns: subGrid.Columns(
subGrid.Column(header: "", format: @<text><input id="select" name="select" type="checkbox" @(@item.ischeck ? "checked='checked'" : "") value="" /></text> , style: "text-center checkbox-width SmallCols"), subGrid.Column("username", "Username"),
subGrid.Column("firstname", "Firstname"),
subGrid.Column("lastname", "Lastname")
)
);
}),
grid.Column(format: (item2) =>
{
WebGrid subGrid2 = new WebGrid(source: item2.Users_role);
return subGrid2.GetHtml(
htmlAttributes: new { id = "subT", @class = "tableRowDivider", style = "display:none;border-top:solid 1px" },
columns: subGrid2.Columns(
subGrid2.Column("firstname", "Users", format: (item3) => item3.lastname + ", " + item3.firstname)
)
);
}),
grid.Column("", "", format: @<tr class="noclass" style="height:10px; border:none;"><td style="border:none;"></td></tr>)
)
)