如何在数据库中的mvc中显示webgrid中的数据

人气:593 发布:2022-09-22 标签:

问题描述

如何在数据库中显示webgrid中的数据。我在sql数据库中使用。编程语言c# 请帮助。

解决方案

从数据库中选择所有行到列表/集合模型。当您调用视图时,您必须通过

 View(collectionOfModel); 

在视图页面上调用它,声明

 @ model IEnumerable <   model  >   <   / model  > ;  

使用剃须刀定义标题和用户foreach ...

< div < span class =code-keyword> class  =   datagrid >  < table> < thead> < tr> < th>移动号码 < /   th  >   < th>家庭电话号码 < /   th  >   < th> < /   th  >   < /   tr  >   < /   thead  >   @foreach(  var  item  in  Model) {< tr> < td>  @ Html.DisplayFor(modelItem = >  item.MobileNo) < /   td  >  < td>  @ Html.DisplayFor(modelItem = >  item.HomePhoneNo) < /   td  >  < td>  @ Html.ActionLink( 编辑, 编辑, new  {id = item.Id})|  @ Html.ActionLink( 详细信息, 详细信息, new  {id = item.Id})|  @ Html.ActionLink( 删除, 删除, new  {id = item.Id}) < /   td  >   < /   tr  >  }   < /   table  >   < /   div  >  

how to show data in webgrid from database. i am use in sql database. programming language c# please help.

解决方案

select all rows from database into a list/Collection of Model. When you call the view, you have to call it by

View(collectionOfModel);

on view page, declare

@model IEnumerable<model>
</model>

Define header and user foreach using razor...

<div class="datagrid">
    <table>
        <thead>
            <tr>
                <th>Mobile No
                </th>
            
                <th>Home Phone No
                </th>
                
                <th></th>
            </tr>
        </thead>
        @foreach (var item in Model)
        {
            <tr>
                <td>
                    @Html.DisplayFor(modelItem => item.MobileNo)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.HomePhoneNo)
                </td>                      
                 <td>
                    @Html.ActionLink("Edit", "Edit", new { id = item.Id }) |
                    @Html.ActionLink("Details", "Details", new { id = item.Id }) |
                    @Html.ActionLink("Delete", "Delete", new { id = item.Id })
                </td>
            </tr>
        }

    </table>
</div>

871