I have one Parent table and its child table.I have to display title from parent and child table on page as given below in MVC project:
I know I have to use nested foreach on view to display this data like given below:
foreach(var ptitle in parents)
{
<li>@model.title</li>
foreach(var pchild in parents.childs)
{
<li>@model.childtitle</li>
}
}
I am using database first approach so what will be the linq query to get such type of result
thanks
Assume that parent is
User
andProduct
is their childs. Here is your entities.You can create viewmodel and collect your data to show:
In action collect data:
And In view:
You can query the children and group them by their parent name. This assumes a ParentClient=>Client relationship.