Referring to the original code here, which works perfectly.

In the LoadData.cshtml file, we find the following code:

var data = "";
foreach(var row in rows){
    data += "<tr><td>" + row.ProductID + "</td><td>" + row.ProductName + 
            "</td><td>" + row.UnitPrice + "</td></tr>";
}

It's working fine when the code is within a single loop:

foreach(var row in rows){
    ... //some code here but no nested foreach loop or loop but only <td> or <tr>
}

However, I was thinking about a broader and more general nested function. What if we have a code like:

foreach{
    ... //some divs here
    foreach{
        ... //some divs here
        row.ProductID row.ProductName
    }
}

How can we implement the load on scroll function in case of such a case?

EDIT

I want to implement the following code:

                                                        @foreach(var rowfollow in getfollowingusernamedata){
                                                        following_username = rowfollow.student_username;
                                                        <div class="panel-body">
                                                            <div class="activity-stream">
                                                                @foreach(var statusrow in db.Query(selectstatuscommand, session_username, following_username)){
                                                                <div class="media">
                                                                    <a class="pull-left" href="profile.cshtml?username=@statusrow.status_username">
                                                                        <img class="media-object" src="@statusrow.status_avatar" alt="@statusrow.status_firstname @statusrow.status_lastname">
                                                                    </a>
                                                                    @if(statusrow.status_username.ToString() == session_username.ToString()){
                                                                        <a class="pull-right" id="modal-delete" href="#modal-container-@statusrow.status_id" role="button"data-toggle="modal"> Delete </a>
                                                                    }
                                                                    <div class="media-body">
                                                                        <h4 class="media-heading"><a href="profile.cshtml?username=@statusrow.status_username">@statusrow.status_firstname @statusrow.status_lastname</a></h4>
                                                                         <p>@statusrow.status_body</p>
                                                                        <img src="@statusrow.status_image" class="statusimage">
                                                                        <form class="form-comment" method="post" action="" id="commentform">
                                                                            <div class="form-group">
                                                                                <input type="text" class="form-control" placeholder="Write a comment ..." name="commentbody">
                                                                                <input type="hidden" class="form-control" value="@statusrow.status_id" name="commentstatusid" style="display: none;">
                                                                                <button type="submit" class="btn btn-primary" value="sharecomment" name="button" style="display: none;">Submit</button>
                                                                            </div>
                                                                        </form>
                                                                        @foreach(var commentrow in db.Query(getcommentcommand, @statusrow.status_id)){
                                                                        <div class="media">
                                                                            @foreach(var getuserId in db.Query("SELECT student_firstname, student_lastname, student_avatar, student_username from student where student_id = @0", @commentrow.comment_userid)){
                                                                            <a class="pull-left" href="profile.cshtml?username=@getuserId.student_username">
                                                                                <img class="media-object" src="@getuserId.student_avatar" alt="Sarah Cole">
                                                                            </a>
                                                                            <div class="media-body">
                                                                                <h4 class="media-heading"><a href="profile.cshtml?username=@getuserId.student_username">@getuserId.student_firstname @getuserId.student_lastname</a></h4>
                                                                                <p>@commentrow.comment_body</p>
                                                                                <ul class="list-inline">
                                                                                    <!--<li><a href="#" class="small"><i class="fa fa-thumbs-o-up"></i> Like</a></li>
                                                                                    <li><a href="#" class="small">Comment</a></li>
                                                                                    <li><a href="#" class="small">Share</a></li>-->
                                                                                    <li><span class="muted small"><i class="imoon imoon-alarm fa-fw"></i> @commentrow.comment_time</span></li>
                                                                                </ul>
                                                                            </div>
                                                                            }
                                                                        </div>
                                                                         } 
                                                                    </div>
                                                                </div>
                                                                } 
                                                            </div>
                                                        </div>

                                                        } 

Related posts

Recent Viewed