zoukankan      html  css  js  c++  java
  • MVC 直接把数据库的数据输出到view(太神奇了)

     @model IEnumerable<MvcApplication32.Models.UserInfo>   后台是集合类型了 ,传到前台是model了,用 IEnumerable<>转为集合类型

    @model MvcApplication32.Models.UserInfo           强类型  

    using MvcApplication32.Models;
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.Mvc;
    
    namespace MvcApplication32.Controllers
    {
        public class HomeController : Controller
        {
            //
            // GET: /Home/
            test1Entities db = new test1Entities();
            public ActionResult Index()
            {
              ViewData["data"]= db.UserInfo.ToList();
                return View();
            }
    
        }
    }
    View Code
    @model MvcApplication32.Models.UserInfo
    @using MvcApplication32.Models;
    @{
        Layout = null;
    }
    
    <!DOCTYPE html>
    
    <html>
    <head>
        <meta name="viewport" content="width=device-width" />
        <title>Index</title>
    </head>
    <body>
        <div>
           @foreach (UserInfo item in ViewData["data"] as List<UserInfo>)
          {
              <p>@item.Id</p> 
               <p>@item.UserName</p>
                <p>@item.Age</p>
               <hr />
          }
        </div>
    </body>
    </html>
    View Code
    转载 请注明原文地址并标明转载:http://www.cnblogs.com/laopo 商业用途请与我联系:lcfhn168@163.com
  • 相关阅读:
    unity 凸多形顶点排序
    unity Plane
    Git MAC电脑Git使用
    Spine运行库指南
    VsCode TypeScritp整理Import
    TypeScript 扩展声明文件 .d.ts
    UnityEditor 编辑多个场景里的对象,Revert 预制件实例
    unity 球形插值
    研究生基础咨询
    ACSM-CPT 考试资料
  • 原文地址:https://www.cnblogs.com/laopo/p/4782688.html
Copyright © 2011-2022 走看看