Model添加类 Customers

 using System;
using System.Collections.Generic;
using System.Linq;
using System.Web; namespace WebApplication2.Models
{
public class Customers
{
public string CustomerID { get; set; }
public string CompanyName { get; set; }
public string ContactName { get; set; }
public string ContactTitle { get; set; }
public string Address { get; set; }
public string City { get; set; }
}
}

增加控制器 Cus

 using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using WebApplication2.Models; namespace WebApplication2.Controllers
{
public class CusController : Controller
{
// GET: Cus
public ActionResult Index()
{
List<Customers> customers = new List<Customers>()
{
new Customers{ CustomerID="ALFKI",CompanyName="Alfreds Futterkiste",ContactName="Maria Anders",ContactTitle="Sales Representative",Address="Obere Str. 57?",City="Berlin" },
new Customers{ CustomerID="ALFKI",CompanyName="Alfreds Futterkiste",ContactName="Maria Anders",ContactTitle="Sales Representative",Address="Obere Str. 57?",City="Berlin" },
new Customers{ CustomerID="ALFKI",CompanyName="Alfreds Futterkiste",ContactName="Maria Anders",ContactTitle="Sales Representative",Address="Obere Str. 57?",City="Berlin" },
new Customers{ CustomerID="ALFKI",CompanyName="Alfreds Futterkiste",ContactName="Maria Anders",ContactTitle="Sales Representative",Address="Obere Str. 57?",City="Berlin" },
new Customers{ CustomerID="ALFKI",CompanyName="Alfreds Futterkiste",ContactName="Maria Anders",ContactTitle="Sales Representative",Address="Obere Str. 57?",City="Berlin" },
new Customers{ CustomerID="ALFKI",CompanyName="Alfreds Futterkiste",ContactName="Maria Anders",ContactTitle="Sales Representative",Address="Obere Str. 57?",City="Berlin" },
new Customers{ CustomerID="ALFKI",CompanyName="Alfreds Futterkiste",ContactName="Maria Anders",ContactTitle="Sales Representative",Address="Obere Str. 57?",City="Berlin" },
};
return View(customers);
}
}
}

增加视图 Index

 @model IEnumerable<WebApplication2.Models.Customers>
@{
ViewBag.Title = "Index";
} <h2>Customers</h2>
<table class="table">
<tr>
<th>CustomerID</th>
<th>CompanyName</th>
<th>ContactName</th>
<th>ContactTitle</th>
<th>Address</th>
<th>City</th>
</tr>
@foreach (var item in Model)
{
<tr>
<td>@Html.DisplayFor(cusitem => item.CustomerID)</td>
<td>@Html.DisplayFor(cusitem => item.CompanyName)</td>
<td>@Html.DisplayFor(cusitem => item.ContactName)</td>
<td>@Html.DisplayFor(cusitem => item.ContactTitle)</td>
<td>@Html.DisplayFor(cusitem => item.Address)</td>
<td>@Html.DisplayFor(cusitem => item.City)</td>
</tr>
}
</table>

显示效果

MVC方式显示数据(手动添加数据)的更多相关文章

  1. C# DataGirdview手动添加数据,导出txt文件并自动对齐

    //DataGirdview手动添加数据 private void btnDataGirdView_Click(object sender,EventArgs e) {       dataGridV ...

  2. [Asp.net MVC]Asp.net MVC5系列——添加数据

    目录 概述 显示添加数据时所用表单 处理HTTP-POST 总结 系列文章 [Asp.net MVC]Asp.net MVC5系列——第一个项目 [Asp.net MVC]Asp.net MVC5系列 ...

  3. MySQL之插入数据(添加数据)-INSERT

    基本语法: INSERT 语句有两种语法形式,分别是 INSERT…VALUES 语句和 INSERT…SET 语句. 1.INSERT...VLAUES语句 INSERT VLAUES的语法格式如下 ...

  4. C#向sql server数据表添加数据源代码

    HoverTree解决方案 学习C#.NET,Sql Server,WinForm等的解决方案. 本文链接http://hovertree.com/h/bjaf/0jteg8cv.htm 使用的技术. ...

  5. MVC方式显示数据(数据库)

    新建实体数据模型 选择ADO.NET实体数据模型,名称改为数据库名 因为使用现有数据库,所以选择来自数据库的EF设计器,只演示所以只选择一个表,空模型可后期增加表 选择从数据库更新模型 新建数据库连接 ...

  6. ABP 极简入门教程(二 MVC方式显示数据)

    增加显示菜单 Sample.Web.MVC项目中找到startup目录打开SampleNavigationProvider.cs,根据现有内容添加以下内容 .AddItem( new MenuItem ...

  7. 【性能监控-Perfmon工具】手动添加数据收集器,点击保存时需要输入用户NT AUTHORITY\SYSTEM的密码问题

    发现是有的电脑会弹出这种输入用户NT AUTHORITY\SYSTEM密码的现象,有的电脑不会弹出这个对话框.......仍然没搞懂是为什么? 关键是输入windows用户登录时的密码也不对!!压根不 ...

  8. android: SQLite添加数据

    现在你已经掌握了创建和升级数据库的方法,接下来就该学习一下如何对表中的数据进 行操作了.其实我们可以对数据进行的操作也就无非四种,即 CRUD.其中 C 代表添加 (Create),R 代表查询(Re ...

  9. SQL中CRUD C——create 添加数据 R——read 读取数据 U——update 修改数据 D——delete 删除数据

    在SQL server中对数据库的操作: 删除表:drop table 表名修改表:alter table 表名 添加列add 列名 列类型alter table 表名 drop column 列名 ...

随机推荐

  1. windows 10 enterprize LTSC

    to avtivate the windows 10 enterprize LTSC version, do the following command every 6 months. slmgr - ...

  2. Golang 项目 GOPATH 总结

    查看GOPATH go env 项目里执行:go  get  github/winyh/XXX 命令时, 包会下载到 GOPATH第一个目录下的src文件夹 项目里引入依赖的时候会自动到GOPATH里 ...

  3. UIScrollView实现自动循环滚动广告

    实现效果如下: 功能说明: 程序运行,图片自动循环播放,采用定时器实现; 当用户用手势触摸滑动时,定时器的自动播放取消,停止触摸时,自动无限播放; 代码如下 : 采用封装视图,外部进行调用即可: 1. ...

  4. .net mvc网站集成adfs(ws-fed协议)

    网站地址(本地开发测试):https://localhost:9000 第一步,adfs配置 配置要声明颁发策略(adfs要发送给网站的声明) 选择刚添加的依赖方信任,编辑颁发策略 配置完成 第二步, ...

  5. Docker 镜像的推送(六)

    目录 一.为镜像命名 二.推送到官方 Docker Hub 1.首先得在 Docker Hub 上注册一个账号. 2.在 Docker Host 上登录 3.修改镜像命名 4.镜像上传 5.登录查看上 ...

  6. WordPress获取特色图像的链接地址

    为什么要获取WordPress的特色图像呢? 这主要是因为,我们已经写好了静态模板文件,只有获取WordPress特色图像地址插入进去就可以了,非常方便. 还有就是有的时候,我们需要设置图片的宽度为1 ...

  7. 微信H5支付开发全过程(除内置微信以外的浏览器)

    前言:网上都是~ 呵呵 自己搞 只要花时间 多问客服总会有的 只说程序不说准备工作 自己ID 或者秘钥都准备好了  写的有点儿乱 可以把所有的方法 放在一个文件中调用 public function ...

  8. xml 数组 互相转换方法

    public function xmlToArray($xml) { //将XML转为array $array_data = json_decode(json_encode(simplexml_loa ...

  9. 转:TSDF in Kinect fusion

    KinectFusion中用到的TSDF Fusion 原po:https://blog.csdn.net/qq_31785865/article/details/78524429 最近在看关于稠密三 ...

  10. openlayers集成到vue开发

    openlayer初步加载地图 vue项目搭好后,直接用node js安装ol, 安装好后可以看看安装的版本:我用的是5..2的版本 然后看官网相对应版本的文档,都是英文文档; 官方文档:    ht ...