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>
    

      生成页面如下

  • 相关阅读:
    正则
    在开发过程中调试报表插件详细教程
    在开发过程中调试报表插件详细教程
    页面导出Excel文件总结
    java.lang.IllegalArgumentException: sheetName '' is invalid
    java.lang.ClassCastException: java.util.ArrayList cannot be cast to java.util.Map
    表达式中的一些常用模式.
    C++使用libcurl做HttpClient
    C++ curl跨平台HttpClient
    java.lang.NumberFormatException: empty String
  • 原文地址:https://www.cnblogs.com/bubugao/p/4541951.html
Copyright © 2011-2022 走看看