控制器层

public ActionResult DemoArray()
{ Product[] array = {
new Product {Name = "Kayak", Price = 275M},
new Product {Name = "Lifejacket", Price = 48.95M},
new Product {Name = "Soccer ball", Price = 19.50M},
new Product {Name = "Corner flag", Price = 34.95M}
};
return View(array);
}

模型层

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web; namespace Razor.Models
{
public class Product
{
public int ProductID { get; set; }
public string Name { get; set; }
public string Description { get; set; }
public decimal Price { get; set; }
public string Category { set; get; } }
}

视图层

@model Razor.Models.Product[]

@{
ViewBag.Title = "DemoArray";
Layout = "~/Views/_BasicLayout.cshtml";
} @if (Model.Length > 0)
{
<table>
<thead><tr><th>Product</th><th>Price</th></tr></thead>
<tbody>
@foreach (Razor.Models.Product p in Model)
{
<tr>
<td>@p.Name</td>
<td>$@p.Price</td>
</tr>
}
</tbody>
</table>
}
else
{
<h2>No product data</h2>
}

改造视图层

@using Razor.Models
@model Product[] @{
ViewBag.Title = "DemoArray";
Layout = "~/Views/_BasicLayout.cshtml";
} @if (Model.Length > 0)
{
<table>
<thead><tr><th>Product</th><th>Price</th></tr></thead>
<tbody>
@foreach (Product p in Model)
{
<tr>
<td>@p.Name</td>
<td>$@p.Price</td>
</tr>
}
</tbody>
</table>
}
else
{
<h2>No product data</h2>
}

Razor数组数据的更多相关文章

  1. ember.js:使用笔记4 数组数据的分组显示

    除了之前介绍的将数组数据在一个页面中输出的方法,还可以将数组数据分组,按照点击,在不同页面中分别显示,方法为: Model: 例如:Table Router: 设置一个父对象和子对象设置: this. ...

  2. 使用sharepreferce记录数组数据

    使用sharepreferce记录数组数据 /** * * sharepreference纪录news数据 * * */ private static final String name=" ...

  3. 如何使用postman传数组数据

    如何使用postman传数组数据 在我们做api接口数据调试的时候,大部分是会用到postman的,一般请求数据的参数都是字符串,但是特殊情况下我们是需要传一个数组数据的,那么为了实现这种需求,究竟该 ...

  4. 从文件中读取数组数据————Java

    自己总结一下Java文件的读取类似数组数据的方法,自己可以快速查看. 一.规整化数据: 对于数组数据是一一对应的情况 ArrayList<String> arrayList = new A ...

  5. Excel 二维数组(数据块)旋转/翻转技巧

    Excel 二维数组(数据块)旋转/翻转技巧 原创 2017-12-30 久石六 久石六 工作中遇到个问题,需要将Excel中的数据块或者说二维数组向右旋转90度,才能再加工处理.当然,不是旋转文本方 ...

  6. PHP去除重复的数组数据

    PHP去除重复的数组数据 <?php $input = array("a" => "green","", "red&q ...

  7. [JAVA]JAVA章1 数组数据去重

    一 利用HashSet进行去重 //定义一个数组:有几个重复项 int[] testarray = {1,2,33,4,2,3,44,5,222,3}; //利用HashSet对数组数据去重 Set& ...

  8. 将一个4X4的数组进行逆时针旋转90度后输出,要求原数组数据随机输入

    //将一个4X4的数组进行逆时针旋转90度后输出,要求原数组数据随机输入 #include<stdio.h> int main() { int a[4][4],b[4][4],i,j;// ...

  9. 清空javascript数组数据

    var arrayObj = new Array(); arrayObj.splice(0, arrayObj.length);//清空数组数据

随机推荐

  1. 青蛙的约会 poj 1061

    青蛙的约会 Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 86640   Accepted: 15232 Descripti ...

  2. 关键字super

    1.super,相较于关键字this,可以修饰属性.方法.构造器 2.super修饰属性.方法:在子类的方法.构造器中,通过super.属性或者super.方法的形式,显式的调用父类的指定 属性或方法 ...

  3. Angular2/Ionic2集成Promact/md2.md

    最近想找一套比较完整的基于Material风格的Angular2的控件库,有两个选择一个是Angular官方的Material2,但是这套库的DatePicker控件目前只能支持年月日,不支持时分秒, ...

  4. ASP.NET Core学习日志1

    1.ASP.NET进行了结构化的优化,使框架更为精简,模块化更加明显. 2.ASP.NET Core不再基于System.Web.dll,而是基于细粒度.分解的NuGet包. 3.基础特性: 1.We ...

  5. shell中处理用户输入

    1.使用命令行参数 在shell执行的时候命令行中输入的所有参数可以赋值给一些特殊变量,这些变量成为位置变量参数. 包括: $0返回脚本名称.$1为第一个参数.$2为第二个参数 ...$9第九个参数 ...

  6. Unity调用Android的两种方式:其一、调用jar包

    unity在Android端开发的时候,免不了要调用Java:Unity可以通过两种方式来调用Android:一是调用jar.二是调用aar. 这篇文章主要讲解怎么从无到有的生成一个jar包,然后un ...

  7. [React] Pass a function to setState in React

    In React, when you want to set the state which calculation depends on the current state, using an ob ...

  8. Create an ASP.NET Core web app in Visual Studio Code

    https://www.microsoft.com/net/core#windowscmd https://download.microsoft.com/download/B/9/F/B9F1AF57 ...

  9. POJ 3256 DFS水题

    枚举点 每次都搜一遍 //By SiriusRen #include <cstdio> #include <cstring> #include <algorithm> ...

  10. 将本地的代码上传到网上SVN库

    使用VisualSVN Server创建版本库: https://jingyan.baidu.com/article/db55b609f6aa724ba20a2f6c.html 最详细的教程: htt ...