zoukankan      html  css  js  c++  java
  • MVC--概述、列表显示数据

    运行机制:

     列表显示数据:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    
    namespace Mvc1.Models
    {
        public class UsersData
        {
            DataClasses1DataContext conn = new DataClasses1DataContext();
    
            //public UsersData()
            //{
     
            //}
    
            public List<Users> Select()
            {
                return conn.Users.ToList();
            }
        }
    }
    Models
    <%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<dynamic>" %>
    <%@ Import Namespace="Mvc1.Models" %>
    <!DOCTYPE html>
    
    <html>
    <head runat="server">
        <meta name="viewport" content="width=device-width" />
        <title>Index</title>
    </head>
    <body>
        <table style="background-color:navy;100%;text-align:center;">
            <tr style="color:white;">
                <td>用户名</td>
                <td>密码</td>
                <td>昵称</td>
                <td>性别</td>
                <td>生日</td>
                <td>民族</td>
                <td>地区</td>
            </tr>
    
            <%
                List<Users> list = new UsersData().Select();
                foreach(Users u in list)
                {
            %>
    
            <tr style="background-color:white;">
                <td><%=u.username %></td>
                <td><%=u.password %></td>
                <td><%=u.nickname %></td>
                <td><%=u.gender?"":"" %></td>
                <td><%=u.birthday.ToString("yyyy-MM-dd") %></td>
                <td><%=u.Nation1.Name %></td>
                <td><%=u.area %></td>
            </tr>
            <%
                } 
            %>
        </table>
    </body>
    </html>
    Views
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.Mvc;
    using Mvc1.Models;
    
    namespace Mvc1.Controllers
    {
        public class HomeController : Controller
        {
            //
            // GET: /Home/
    
            public ActionResult Index()
            {
                return View();
            }
        }
    }
    Controllers

  • 相关阅读:
    单点登录实现机制
    简单工厂
    单例模式
    Remoting
    Redis编码问题
    减少手机页面跳转的方法(转)
    失血模型,充血模型
    Hashtable
    Why we don’t recommend using List<T> in public APIs
    Aggregate累加器
  • 原文地址:https://www.cnblogs.com/xiao55/p/6047677.html
Copyright © 2011-2022 走看看