MVC方式显示数据(手动添加数据)
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方式显示数据(手动添加数据)的更多相关文章
- C# DataGirdview手动添加数据,导出txt文件并自动对齐
//DataGirdview手动添加数据 private void btnDataGirdView_Click(object sender,EventArgs e) { dataGridV ...
- [Asp.net MVC]Asp.net MVC5系列——添加数据
目录 概述 显示添加数据时所用表单 处理HTTP-POST 总结 系列文章 [Asp.net MVC]Asp.net MVC5系列——第一个项目 [Asp.net MVC]Asp.net MVC5系列 ...
- MySQL之插入数据(添加数据)-INSERT
基本语法: INSERT 语句有两种语法形式,分别是 INSERT…VALUES 语句和 INSERT…SET 语句. 1.INSERT...VLAUES语句 INSERT VLAUES的语法格式如下 ...
- C#向sql server数据表添加数据源代码
HoverTree解决方案 学习C#.NET,Sql Server,WinForm等的解决方案. 本文链接http://hovertree.com/h/bjaf/0jteg8cv.htm 使用的技术. ...
- MVC方式显示数据(数据库)
新建实体数据模型 选择ADO.NET实体数据模型,名称改为数据库名 因为使用现有数据库,所以选择来自数据库的EF设计器,只演示所以只选择一个表,空模型可后期增加表 选择从数据库更新模型 新建数据库连接 ...
- ABP 极简入门教程(二 MVC方式显示数据)
增加显示菜单 Sample.Web.MVC项目中找到startup目录打开SampleNavigationProvider.cs,根据现有内容添加以下内容 .AddItem( new MenuItem ...
- 【性能监控-Perfmon工具】手动添加数据收集器,点击保存时需要输入用户NT AUTHORITY\SYSTEM的密码问题
发现是有的电脑会弹出这种输入用户NT AUTHORITY\SYSTEM密码的现象,有的电脑不会弹出这个对话框.......仍然没搞懂是为什么? 关键是输入windows用户登录时的密码也不对!!压根不 ...
- android: SQLite添加数据
现在你已经掌握了创建和升级数据库的方法,接下来就该学习一下如何对表中的数据进 行操作了.其实我们可以对数据进行的操作也就无非四种,即 CRUD.其中 C 代表添加 (Create),R 代表查询(Re ...
- SQL中CRUD C——create 添加数据 R——read 读取数据 U——update 修改数据 D——delete 删除数据
在SQL server中对数据库的操作: 删除表:drop table 表名修改表:alter table 表名 添加列add 列名 列类型alter table 表名 drop column 列名 ...
随机推荐
- 采购订单审批与撤销审批BAPI
*"---------------------------------------------------------------------- *"*"本地接口: *& ...
- springboot Thymeleaf中格式化jsr310新日期时间类(LocalDateTime,LocalDate)--thymeleaf格式化LocalDateTime,LocalDate等JDK8新时间类
依赖maven包 <dependency> <groupId>org.thymeleaf.extras</groupId> <artifactId>th ...
- Tips for Conda
管理环境 创建环境 基于 python3.6 创建一个名为test_py3的环境 conda create -n test_py3 python=3.6 基于 python2.7 创建一个名为test ...
- SpringMvc+ajax跨域请求时,出现options类型的请求并返回403的解决方案
在使用 $.ajax({ url:'http://127.0.0.1:8081/rest/ccxxx/xxxx', type:'POST', dataType:"json", co ...
- 给 textbox TextMode="password" 赋值后显示出来
在做一个修改用户资料的页面的时候,发现用 <asp:TextBox ID="txtPwd" runat="server" TextMode="P ...
- 【Leetcode_easy】682. Baseball Game
problem 682. Baseball Game solution: 没想到使用vector! class Solution { public: int calPoints(vector<s ...
- 【c# 学习笔记】继承
在c#中,一个类可以继承另外一个已有的类(密封类除外),被继承的类称为基类(或父类),继承的类称为派生类(或子类),子类将获得基类 除构造函数和析构函数以外的所有成员.此外,静态类是密封的,也不能被继 ...
- 关于远程链接 redis的坑·
今天遇到了一个问题,在redis.conf 中 将 bind: 注释掉bind 127.0.0.1 仍然不行 其实是要把bind 127.0.0.1 改为 0.0.0.0 才行 下面附赠详细过程 查看 ...
- cv2---imread---error
when I use the cv2.imred() which is absolute path path = r'C:\\Users\\hp\\Desktop\\常用Python代码\\mycv ...
- java根据模板生成pdf
原文链接:https://www.cnblogs.com/wangpeng00700/p/8418594.html 在网上看了一些Java生成pdf文件的,写的有点乱,有的不支持写入中文字体,有的不支 ...