Convert html foreach loop data to webgrid using asp.net mvc razor view

coder rock 196 Reputation points
2021-06-20T15:28:16.81+00:00

Below html table is filling using two loop condition, and same i want using two loop conditions to fill Webgrid

<table class="awe-ajaxlist table_dashboard">  
                <tr class="tbl_header">  
                    <td>  
                        Payor  
                    </td>  
                    <td>  
                        Check #  
                    </td>  
                    <td>  
                        Billed Amount  
                    </td>  
                    <td>  
                        Paid Amount  
                    </td>  
                    <td>  
                        Check Date  
                    </td>  
                    <td>Download File</td>  
                </tr>  
                @foreach (var i in (List<MyDME.Data.Model.ERNFileRequestDTO>)ViewBag.lst)  
                {  
                    for (int j = 0; j < i.Parse835Details.storedChkNo.Count; j++)  
                    {  

                        <tr>  
                            <td>  
                                @i.Parse835Details.storedPayorName[j]  
                            </td>  
                            <td>  
                                @i.Parse835Details.storedChkNo[j]  
                            </td>  
                            <td>  
                                @i.Parse835Details.storedTotalBilled[j]  

                            </td>  
                            <td>  
                                @i.Parse835Details.storedTotalPaid[j]  

                            </td>  
                            <td>  
                                 @(i.Parse835Details.storedChkDate[j].Substring(4, 2) + "/" + i.Parse835Details.storedChkDate[j].Substring(6, 2) + "/" + i.Parse835Details.storedChkDate[j].Substring(0, 4))  

                            </td>  
                            <td>  
                                <a href='/PatientManagement/DownloadUploadedDocument?fileName=@Html.Raw(i.path)'>Download</a>  

                            </td>  
                        </tr>  


                    }  

                }  
            </table>  

I have tried to fill one field in web grid by using below code but this code is not working for me.

@{  
                          var grid2 = new WebGrid();  
                        List<WebGridColumn> cols = new List<WebGridColumn>();  
                        foreach (var i in (List<MyDME.Data.Model.ERNFileRequestDTO>)ViewBag.lst)  
                        {  
                            for (int j = 0; j < i.Parse835Details.storedChkNo.Count; j++)  
                            {  
                                cols.Add(grid2.Column("Payor", format:@<text> <span class="display-mode">@i.Parse835Details.storedPayorName[j]</span> </text>, style: "col1Width"));  

                            }  
                        }  

                    }  

when i am click debugging mode after code line complete on this line var grid2 = new WebGrid(); the following error is showing.

107266-error1.png

ASP.NET
ASP.NET
A set of technologies in the .NET Framework for building web applications and XML web services.
3,270 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,277 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Yijing Sun-MSFT 7,066 Reputation points
    2021-06-21T08:19:23.557+00:00

    Hi @coder rock ,
    Do you want to know about these red lines? These are not errors. They caused by not loading columnnames and pagecount.
    How do your WebGird? Do you have error message?
    Best regards,
    Yijing Sun


    If the answer is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our  documentation  to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments