Tuesday 9 July 2019

Dynamic Tables in Razor View From Model (Dynamic Header and body using model)

//////////////////////


<table class="table table-bordered table-hover nowrap display" id="tblID" style="width:100%">
        <thead>
            <tr>
                <th class="text-center" style="width:5%;">
                    SNo.
                </th>
                @{var cnth = 0; }
                @foreach (var property in Model.GetType().GetGenericArguments()[0].GetProperties())
                {

                    if (cnth > 2)
                    {
                        <th>@property.Name</th>
                    }
                    cnth++;
                }
                <th class="text-center">
                    Action
                </th>
            </tr>
        </thead>
        <tbody>
            @{var cntb = 0; }
            @{ var cnt = 0;}
            @foreach (var item in Model)
            {
                cntb = 0;
                <tr>
                    @foreach (var property in item.GetType().GetProperties())
                    {
                        if (cntb == 0)
                        {
                            <td class="text-center" style="width:5%;">
                                @(cnt += 1)
                            </td>
                        }
                        if (cntb > 2)
                        {
                            <td>@property.GetValue(item)</td>
                        }
                        cntb++;
                    }
                    <td class="p-0 text-center" style="vertical-align:middle;">
                        @if (item.PatientCount > 0)
                        {
                            <a href="#"><i class="glyphicon glyphicon-download f-18"></i></a>
                        }
                    </td>
                </tr>
            }
        </tbody>
    </table>

No comments:

Post a Comment

Excel Sort values in ascending order using function TEXTJOIN

 Excel ::  Text ::  1,3,5,2,9,5,11 Result :: 1,2,3,5,5,9,11 Formula ::     TEXTJOIN ( ",",1,SORT(MID(SUBSTITUTE( A1 ,","...