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

  • 相关阅读:
    SSH 远程执行任务
    C# 创建压缩文件
    迁移 SQL Server 到 Azure SQL 实战
    在 Azure 上部署 Asp.NET Core Web App
    linux kill 命令
    VS 远程调试 Azure Web App
    Azure 基础:自定义 Table storage 查询条件
    NSOperation的使用细节 [2]
    NSOperation的使用细节 [1]
    [翻译] SSKeychain
  • 原文地址:https://www.cnblogs.com/xiao55/p/6047677.html
Copyright © 2011-2022 走看看