zoukankan      html  css  js  c++  java
  • MVC入门——列表页

    创建控制器UserInfoController

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.Mvc;
    using MvcApplicationStudy.Models;
    namespace MvcApplicationStudy.Controllers
    {
        public class UserInfoController : Controller
        {
            //
            // GET: /UserInfo/
    
            public ActionResult Index()
            {
                TestEntities db = new TestEntities();
                var userInfoList = db.UserInfo.Where<UserInfo>(c => true);
                List<UserInfo> list = userInfoList.ToList();
               // ViewBag.Model = list;
                //return View();
                return View(list);
            }
    
        }
    }
    

      添加视图

    @model IEnumerable<MvcApplicationStudy.Models.UserInfo>
    @{
        Layout = null;
    }
    
    <!DOCTYPE html>
    
    <html>
    <head>
    
        <meta name="viewport" content="width=device-width" />
    
        <title>Index</title>
    </head>
    <body>
        <div>
            <table>
                 <tr><th>编号</th><th>用户名</th><th>密码</th><th>时间</th><th>详细</th><th>删除</th><th>修改</th></tr>
             @*   @foreach(var userInfo in ViewBag.Model){
                    <tr>
                        <td>@userInfo.ID</td>
                        <td>@userInfo.UserName</td>
                        <td>@userInfo.UserPwd</td>
                        <td>@userInfo.RegTime</td>
                        <td>详细</td>
                        <td>删除</td>
                        <td>修改</td>
                    </tr>
                
                }*@
                @foreach(var item in Model){
                     <tr>
                        <td>@Html.DisplayFor(modelItem=>item.ID)</td>
                        <td>@Html.DisplayFor(modelItem=>item.UserName)</td>
                        <td>@Html.DisplayFor(modelItem=>item.UserPwd)</td>
                        <td>@Html.DisplayFor(modelItem=>item.RegTime)</td>
                        <td>@Html.ActionLink("详细", "ShowDetail", new{ id=item.ID})</td>
                        <td>@Html.ActionLink("删除", "DeleteUserInfo", new { id = item.ID }, new { @class="del"})</td>
                        <td>@Html.ActionLink("修改", "EditUserInfo", new { id=item.ID})</td>
                    </tr> 
                }
            </table>
        </div>
    </body>
    </html>
    

      生成页面如下

  • 相关阅读:
    NIO通道的学习笔记
    Struts学习笔记(启动过程)
    Struts2学习笔记(ResultType)
    11
    编写类String的构造函数、析构函数和赋值函数(转载)
    new与malloc的区别
    不用判断语句,求两个数中大的那个
    delete p和delete[] p的区别(转)
    (转)虚函数和纯虚函数区别
    不借助第三个变量交换两个整数的值
  • 原文地址:https://www.cnblogs.com/bubugao/p/4541951.html
Copyright © 2011-2022 走看看