Hi dharmendr,
Thanks for your reply. But still i have some complications to acheive this. You had classified with entities. But i am using Datatable to list.
But while clicking details button, modal popup showing with empty rows.
Kindly let me know where i missed to bind.
Thanks in Advance.
Here my code follows.
Model:
public class ProjectUpload
{
public int GROUPNO { get; set; }
public string ProjectCode { get; set; }
public string ActivityCode { get; set; }
public string Originatorname { get; set; }
public string COMPANYCODE { get; set; }
public List<ProjectUpload> ProjectUploadinfo { get; set; }
}
Controller:
List<ProjectUpload> projectlist = new List<ProjectUpload>();
if(dtPL.Rows.Count>0)
{
for (int i = 0; i < dtPL.Rows.Count; i++)
{
projectlist.Add(new ProjectUpload
{
GROUPNO = Convert.ToInt32(dtPL.Rows[i]["GroupNo"].ToString()),
ProjectCode = Convert.ToString(dtPL.Rows[i]["ProjectCode"].ToString()),
ActivityCode = Convert.ToString(dtPL.Rows[i]["ActivityCode"].ToString()),
Originatorname = Convert.ToString(dtPL.Rows[i]["BuyerName"].ToString()),
COMPANYCODE = Convert.ToString(dtPL.Rows[i]["COMPANYCODE"].ToString().Trim()),
ProjectUploadinfo = projectlist.Where(com => com.ProjectCode == dtPL.Rows[i]["ProjectCode"].ToString()).ToList(),
}
}
}
ViewBag.ProjectList = projectlist;
View:
<div class="table-responsive" style="overflow-x:scroll;">
<table id="tblHeader" class="table table-striped table-bordered table-hover" border="1" style="display:compact;" width="100%" cellspacing="0">
<thead>
<tr>
<th>GroupNo</th>
<th>ProjectCode</th>
<th>Company Code</th>
<th></th>
</tr>
</thead>
<tbody>
@if (ViewBag.ProjectList != null)
{
foreach (var item in ViewBag.ProjectList)
{
<tr>
<td><span>@item.GROUPNO</span></td>
<td><span>@item.ProjectCode</span></td>
<td><span>@item.CompanyCode</span></td>
<td>
<button type="button" class="btn btn-warning" data-toggle="modal" data-target="#@item.ProjectCode">Details</button>
<div class="modal fade" id="@item.ProjectCode">
<div class="modal-dialog modal-dialog-centered">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title">Details</h4>
<button type="button" class="close" data-dismiss="modal">×</button>
</div>
<div class="modal-body">
<table class="table">
<tr>
<th>Activity Code</th>
<th>Buyer Name</th>
</tr>
<tbody>
@foreach (AAF.Models.ProjectUpload order in item.ProjectUploadinfo)
{
<tr>
<td>@order.ActivityCode</td>
<td>@order.BuyerName</td>
</tr>
}
</tbody>
</table>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
</td>
</tr>
}
}
</tbody>
</table>
</div>