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

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

  • 相关阅读:
    项目部署在windows下的tomcat里
    获取tomcat端口号的三种方式
    windows 下载安装github
    Exception in thread "main" java.lang.IllegalArgumentException: Illegal character in query at index 189......
    HTTP协议头了解
    服务器nginx安装
    php源码安装
    php简化指令,以及php.ini配置
    配置php7 以支持swoole
    swoole install
  • 原文地址:https://www.cnblogs.com/wwr01/p/7711966.html
Copyright © 2011-2022 走看看