Hi,
Thanks for the help. The following link was very helpful to me in doing my task. They have used EF, but I am getting data from WebAPI, I have changed code little bit. For Reference I am adding my code here.
http://www.dotnetawesome.com/2014/07/nested-webgrid-with-expand-collapse-in-aspnet-mvc4.html
[Route("~/EnquiryDetails/Index")]
[Authentication]
public ActionResult EnquiryDetails()
{
//All Enquiry Details
List<EnquiryAllModelBO> objEnEnquiryAllModelBOList = null;
EnquiryAllModelBO objEnquiryAllModelBO = null;
List<ParentEnquiryModelBO> objParentEnquiryModelBOList = GetParentEnquiryDetails();
for (int i = 0; i < objParentEnquiryModelBOList.Count; i++)
{
objEnEnquiryAllModelBOList= new List<EnquiryAllModelBO>();
objEnquiryAllModelBO=new EnquiryAllModelBO();
objEnquiryAllModelBO.ParentEnquiryList = objParentEnquiryModelBOList[i];
objEnquiryAllModelBO.ChildEnquiryList = GetChildEnquiryDetails(objParentEnquiryModelBOList[i].ProductEnquiryID);
objEnEnquiryAllModelBOList.Add(objEnquiryAllModelBO);
}
return View(objEnEnquiryAllModelBOList);
}
private List<ParentEnquiryModelBO> GetParentEnquiryDetails()
{
List<ParentEnquiryModelBO> objParentEnquiryModelBOList = new List<ParentEnquiryModelBO>();
string stringData = string.Empty;
//ViewBag.UserName = _Username;
using (var client = new HttpClient())
{
//Calling WebAPI, later need to read from Web.Config
response = client.GetAsync("http://localhost:64297/Admin/Enquiry/GetParentEnquiry/").Result;
//response = client.GetAsync(_ServiceURL_Admin_Get + "/" + _Username + "/" + SessionManagement.Current.CountryID).Result;
if (response.IsSuccessStatusCode)
{
stringData = response.Content.ReadAsStringAsync().Result;
objParentEnquiryModelBOList = JsonConvert.DeserializeObject<List<ParentEnquiryModelBO>>(stringData);
}
else //web api sent error response
{
//log response status here..
ModelState.AddModelError(string.Empty, "Server error. Please contact administrator.");
}
}
return objParentEnquiryModelBOList;
}
private List<ChildEnquiryModelBO> GetChildEnquiryDetails(int ProductEnquiryID)
{
List<ChildEnquiryModelBO> objChildEnquiryModelBOList = new List<ChildEnquiryModelBO>();
string stringData = string.Empty;
//ViewBag.UserName = _Username;
using (var client = new HttpClient())
{
//Calling WebAPI, later need to read from Web.Config
response = client.GetAsync("http://localhost:64297/Admin/Enquiry/GetChildEnquiry/"+ ProductEnquiryID).Result;
//response = client.GetAsync(_ServiceURL_Admin_Get + "/" + _Username + "/" + SessionManagement.Current.CountryID).Result;
if (response.IsSuccessStatusCode)
{
stringData = response.Content.ReadAsStringAsync().Result;
objChildEnquiryModelBOList = JsonConvert.DeserializeObject<List<ChildEnquiryModelBO>>(stringData);
}
else //web api sent error response
{
//log response status here..
ModelState.AddModelError(string.Empty, "Server error. Please contact administrator.");
}
}
return objChildEnquiryModelBOList;
}
public class EnquiryAllModelBO
{
public ParentEnquiryModelBO ParentEnquiryList { get; set; }
public List<ChildEnquiryModelBO> ChildEnquiryList { get; set; }
}
public class ParentEnquiryModelBO
{
public int ProductEnquiryID { get; set; }
public DateTime EnquiryDate { get; set; }
public string CustomerName { get; set; }
public string Email { get; set; }
public string PhoneNumber { get; set; }
}
public class ChildEnquiryModelBO
{
public int ProductLineID { get; set; }
public int ProductEnquiryID { get; set; }
public int InventoryConfigID { get; set; }
//public string ProductName { get; set; }
public int Qty { get; set; }
}