zoukankan      html  css  js  c++  java
  • MVC架构+ef 添加、删除、查询用户。。。

    首先

    在Controller中修改Index方法,添加相关View, 显示所有用户

     public ActionResult Index()
            {
                return View(db.SysUsers);
            }

    注意

    Views 里面的Account到*.cshtml 顶部添加强类型声明(*代表名字)

    @model IEnumerable<MVCDemo.Models.SysUser>

    body中添加个table用来显示数据

    <body>
        <div>
            <p>@Html.ActionLink("Create New","Create")</p>
            <table>
                <tr>
                    <th>
                        @Html.DisplayNameFor(model=>model.UserName)
                    </th>
                    <th>
                        @Html.DisplayNameFor(model => model.Email)
                    </th>
                    <th></th>
                </tr>
                @foreach (var item in Model)
                {
                     <tr>
                         <td>
                             @Html.DisplayFor(modelItem=>item.UserName)
                         </td>
                         <td>
                             @Html.DisplayFor(modelItem => item.Email)
                         </td>
                         <td>
                             @Html.ActionLink("Details", "Details", new{ id=item.ID})
                             @Html.ActionLink("Edit", "Edit", new { id = item.ID })
                             @Html.ActionLink("Delete", "Delete", new { id = item.ID })
                         </td>
                     </tr>
                }
            </table>
        </div>
    </body>

     @Html.ActionLink("Details", "Details", new{ id=item.ID})
     @Html.ActionLink("Edit", "Edit", new { id = item.ID })
     @Html.ActionLink("Delete", "Delete", new { id = item.ID })

    生成一个相同controller下的路由地址。

    在Controller中增加相应的方法 Create  Edit Delete

    然后分别添加相应的视图 

    *.cshtml 的最顶端添加

    @model MVCDemo.Models.SysUser

    每个分别添加相应的代码

    里面比较重要的  便于理解代码

    DisplayNameFor (model=>model.xxx):生成纯文本,显示xxx列名

    DisplayFor (model=>model.xxx):生成纯文本,显示xxx列的内容

    LableFor:生成一个Lable标签

    EditorFor : 生成一个text类型的input

    PasswordFor : 类似于EditorFor, 隐藏文本内容

    ActionLink :生成一个<a>标签

    BeginForm : 生成一个表单

    实现了简单的添加删除修改等、、、

  • 相关阅读:
    TableEx 控件 v1.0 [原创][免费][开源]
    js刷新页面
    SimpleAjax 开发包 v3.1 (简单的Ajax)
    oracle中的''空字符串和null居然是等价的
    HTTP 错误大全
    Ext2.0 form使用实例
    isqlweb (Web版 SQL Server 管理器)
    关于软件版本
    我的第一个C++程序——方块游戏 v1.0
    轻松实现UltraWebGrid中的分页控制
  • 原文地址:https://www.cnblogs.com/wwr01/p/7711966.html
Copyright © 2011-2022 走看看