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 : 生成一个表单

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

  • 相关阅读:
    从 Qt 的 delete 说开来
    Qt信号槽的一些事
    Qt 线程基础(QThread、QtConcurrent等)
    QThread使用——关于run和movetoThread的区别
    重点:怎样正确的使用QThread类(注:包括推荐使用QThread线程的新方法QObject::moveToThread)
    重要:C/C++变量的自动初始化
    C++中基类的析构函数为什么要用virtual虚析构函数
    如何打印Qt中的枚举所对应的字符串
    用route命令解决多出口的问题
    C/C++预处理指令
  • 原文地址:https://www.cnblogs.com/wwr01/p/7711966.html
Copyright © 2011-2022 走看看