TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Manoj Maharana
NA
362
128k
dynamic foreach loop on parent child combination in MVC.net
Sep 6 2016 7:56 AM
i have a parent id and child id...this child id is also the parent of some child..i.e. parent having multiple child..and these multiple child having parent of some child..
example:Suppose A is the parent of B,C,D and E...if B has some child name G,H,I and G has some child having J,K..now how to use foreach loop here in this case???
now how to use foreach loop???
Here is the code but it works for only single parent child relationship(suppose A having B,C,D child):
enter code here
@model Abacus_CMS.Models.AbacusModel
@{
Layout =
null
;
//for parent
var ParentCatagoryList = Model.AbacusMenuList.Where(x => x.ParentCatagoryId == 0).ToList();
//for parentchild
var ParentChildMenuList = Model.AbacusChildMenuList.Where(x => x.ChildParentId != 0).ToList();
}
@*
//add sidebar parent and their childname*@
@
if
(ParentCatagoryList.Count > 0)
{
<ul
class
=
"page-sidebar-menu "
data-auto-scroll=
"true"
data-slide-speed=
"200"
>
<li
class
=
"sidebar-toggler-wrapper"
>
<!-- BEGIN SIDEBAR TOGGLER BUTTON -->
<div
class
=
"sidebar-toggler"
>
</div>
<!-- END SIDEBAR TOGGLER BUTTON -->
</li>
@
foreach
(var item
in
ParentCatagoryList)
{
<li>
<a href=
"@Url.RouteUrl("
GettingStarted
", new {catname =HttpUtility.UrlEncode(item.Name.Replace(' ', '-')) })"
id=
"@item.Name.Replace(' ', '-').ToLower()"
>
<i
class
=
"icon-user"
></i>
<span
class
=
"title"
style=
"margin-left: -24px;"
>@item.Name</span>
@*<span
class
=
"arrow "
style=
"height: 4px;"
></span>*@
<span
class
=
"icon-01"
style="
float
: left;
margin-top: -2px;
margin-left: 20px;">
<i
class
=
"fa fa-angle-right"
aria-hidden=
"true"
></i>
</span>
</a>
<ul
class
=
"sub-menu"
>
@
foreach
(var childitem
in
ParentChildMenuList)
{
if
(item.Id == childitem.ChildParentId)
{
<li style=
"margin-left: 38px;"
>
<span style=
"background: #999999; width: 4px; height: 4px; float: left; margin-left: -20px; margin-top: 13px;"
></span>
<a href=
"@Url.RouteUrl("
GettingStarted
", new { catname = HttpUtility.UrlEncode(childitem.ChildName.Replace(' ', '-'))})"
id=
"@childitem.ChildName.Replace(' ', '-').ToLower()"
>@childitem.ChildName</a>
</li>
}
}
</ul>
</li>
}
</ul>
}
here one loop i get parent and another loop i get child...
soo for multiple combination what should i do??
Reply
Answers (
1
)
how to send product details with image by mail in .net c#
listview pagenation