如何在数据库中的mvc中显示webgrid中的数据 [英] how to show data in webgrid in mvc from database

查看:66
本文介绍了如何在数据库中的mvc中显示webgrid中的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在数据库中显示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>


这篇关于如何在数据库中的mvc中显示webgrid中的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆