Ramco Ramco

Ramco Ramco

  • 469
  • 2.8k
  • 390k

How to use Model

Jun 30 2021 4:27 PM

Hi

   How i can use below code in a view where List of Locations is also required & Individual Location also.

                   <table class="table table-striped table-hover" id="tblLocation" style="width:100%">
                            <thead>
                                <tr>
                                    <th>
                                        @Html.DisplayNameFor(model => model.Location.Id)
                                    </th>
                                    <th>
                                        @Html.DisplayNameFor(model => model.Location.Description)
                                    </th>
                                    <th>
                                        @Html.DisplayNameFor(model => model.Location.IsActive)
                                    </th>
                                    <th>Action</th>
                                </tr>
                            </thead>
                            @foreach (var item in Model.Locations)
                            {
                                <tr>
                                    <td>
                                        @Html.DisplayFor(model => item.Id)
                                    </td>
                                    <td>
                                        @Html.DisplayFor(model => item.Description)
                                    </td>
                                    <td>
                                    @if(item.IsActive)
                                    {
                                        <i class='fa fa-check' style="color:Highlight"></i>
                                    }
                                    else
                                    {
                                        <i class='fa fa-times' style="color:red"></i>
                                    }
                                    </td>
                                    <td>
                                        <button id="btnEdit" type="button" class="btn btn-primary btn-sm" style='margin-left:5px'><i class='fa fa-pencil'></i> Edit </button>  
                                        @if (item.IsActive)
                                        {
                                            <button id="btnDelete" type="button" class="btn btn-danger btn-sm" style='margin-left:5px'><i class='fa fa-trash'></i> Delete </button>
                                        }
                                        else
                                        {
                                            <a id='btnDelete' class='btn btn-danger btn-sm disabled' style='margin-left:5px'><i class='fa fa-trash'></i> Delete </a>
                                        }
                                    </td>
                                </tr>
                            }
                        </table>

 

Thanks


Answers (3)