ASP.NET MVC 学习笔记(三),排序加查找
首先先说排序
非常的简单
代码如下
//创建视图
public ViewResult Index()
{
//升序排列
IEnumerable<Product> Prodcuts = repository.Products.OrderBy(x => x.Price);
//下面的是降序排列
repository.Products.OrderByDescending(x => x.Price);
List<Product> p = Prodcuts.ToList();
QuickSort(, p.Count - , p);
string s1 = "";
//List<Product> list= Prodcuts.AsQueryable().OrderBy(x => x.Price).ToList();
// foreach (var item in Prodcuts)
// {
// string p = item.Category;
// }
Prodcuts = p;
return View(Prodcuts);
}
核心语句 orderBy 升序,降序 OrderByDescending
查找数据
1 创建查找的动作方法
[HttpPost]
public ActionResult Query(string Name)
{
IEnumerable<Product> p = repository.Products.Where(x => x.Category== Name||x.ProductName.Contains(Name));
if (p != null)
{
return View("QueryResult", p);
}
else
{
return View("QueryResult",p);
} }
没什么的可解释的,
Html 代码
@using Domain.Entities
@model IEnumerable<Product>
@{
ViewBag.Title = "Index";
} <h2>Index</h2>
@* 查询再这里 *@
@using (Html.BeginForm("Query","Product"))
{
@Html.TextBox("Name");
<input type="submit" value="查询" />
}
<table class="table table-bordered table-striped table-condensed" >
<tr>
<th class="text-center">id</th>
<th class="text-center">产品名</th>
<th class="text-center">描述</th>
<th class="text-center">种类</th>
<th class="text-center">价格</th>
<th class="text-center">删除</th>
</tr>
@foreach (var item in Model)
{
<tr>
<td>@item.ProductID</td>
<td>@Html.ActionLink(item.ProductName, "Edit", new { item.ProductID })</td>
<td>@item.Description</td>
<td>@item.Category</td>
<td>@item.Price.ToString()</td>
<td>
@using (Html.BeginForm("Delete", "Product"))
{
@Html.Hidden("ProductId", item.ProductID)
<input class="btn btn-danger" type="submit" value="删除"/>
}
</td>
</tr> } </table>
<div class="panel-footer">
@Html.ActionLink("添加", "Create", new { @class="btn btn-default"})
</div>
查询结构视图没什么好解释的就一个Foreach
@using Domain.Entities
@model IEnumerable<Product>
@{
ViewBag.Title = "QueryResult";
} <h2>QueryResult</h2> <table border=""> @if (Model.Count()>)
{
foreach (var item in Model)
{
<tr>
<td>@item.ProductName</td>
<td>@item.Description</td>
<td>@item.Category</td>
<td>@item.Price</td>
</tr>
}
}
else
{
<tr>
<td>没有查询到</td>
</tr>
}
</table>
测试结果



ASP.NET MVC 学习笔记(三),排序加查找的更多相关文章
- ASP.NET MVC 学习笔记-2.Razor语法   ASP.NET MVC 学习笔记-1.ASP.NET MVC 基础    反射的具体应用  策略模式的具体应用  责任链模式的具体应用  ServiceStack.Redis订阅发布服务的调用  C#读取XML文件的基类实现
		ASP.NET MVC 学习笔记-2.Razor语法 1. 表达式 表达式必须跟在“@”符号之后, 2. 代码块 代码块必须位于“@{}”中,并且每行代码必须以“: ... 
- ASP.NET MVC学习笔记-----Filter2
		ASP.NET MVC学习笔记-----Filter(2) 接上篇ASP.NET MVC学习笔记-----Filter(1) Action Filter Action Filter可以基于任何目的使用 ... 
- ASP.NET MVC学习笔记-----Filter
		ASP.NET MVC学习笔记-----Filter(1) Filter类型 接口 MVC的默认实现 Description Authorization IAuthorizationFilter Au ... 
- ASP.NET MVC学习笔记-----Filter(2)
		接上篇ASP.NET MVC学习笔记-----Filter(1) Action Filter Action Filter可以基于任何目的使用,它需要实现IActionFilter接口: public ... 
- ASP.NET MVC 学习笔记-7.自定义配置信息    ASP.NET MVC 学习笔记-6.异步控制器  ASP.NET MVC 学习笔记-5.Controller与View的数据传递  ASP.NET MVC 学习笔记-4.ASP.NET MVC中Ajax的应用  ASP.NET MVC 学习笔记-3.面向对象设计原则
		ASP.NET MVC 学习笔记-7.自定义配置信息 ASP.NET程序中的web.config文件中,在appSettings这个配置节中能够保存一些配置,比如, 1 <appSettin ... 
- ASP.NET MVC学习笔记 第三天
		布局: 如果不使用布局页,需要将Layout属性设置为null. @{ Layout = null; } 使用默认布局页: 使用Add View对话框,选择使用布局页(是布局页的名称文本框为空 ... 
- ASP.NET MVC学习笔记(二)笔记
		接下来我们一起了解ASP.NET MVC的最重要的核心技术,了解ASP.NET MVC的开发框架,生命周期,技术细节. 一.Routing与ASP.NET MVC生命周期 1.Routing——网址路 ... 
- ASP.NET MVC 学习笔记(1)
		从头开始系统地学习ASP.NET MVC 为什么要学习ASP.NET MVC?原因很多,可以先来看一下最早的ASP.NET WebForm的一些缺点: 传说中面试经常要问到的ASP.NET WebFo ... 
- ASP.NET MVC  学习笔记 1
		1. 什么是ASP.Net MVC ASP.Net MVC是一种开发Web应用程序的工具(is a web application development framework),采用Model-Vie ... 
- 【ASP.NET MVC 学习笔记】- 07 使用 Entity Framework
		本文参考:http://www.cnblogs.com/willick/p/3304534.html 1.ORM(Object Relation Mapping)工具,是为了解决“关系数据库”和“面向 ... 
随机推荐
- 115. Distinct Subsequences (String; DP)
			Given a string S and a string T, count the number of distinct subsequences of T in S. A subsequence ... 
- .net使用httpHandler添加图片防盗链
			.net使用httpHandler添加图片防盗链1. 配置web.config: <!--图片添加水印的配置--> <httpHandlers> <add verb=&q ... 
- 转---tcp三次握手四次挥手syn fin......
			http://blog.chinaunix.net/uid-22312037-id-3575121.html转自 一.TCP报文格式 TCP/IP协议的详细信息参看<TCP/IP协 ... 
- css菜鸟学习之text-align属性,行内元素,块级元素居中详解
			一.text-align属性 1.text-align用来设置元素中的的文本对齐方式,例如:如果需要设置图片的对齐方式,需要设置图片的父元素的text-align属性: 2.text-align只对文 ... 
- (重要)LRU cache
			[抄题]: [思维问题]: 需要从任何位置访问某数字有没有(重要 ),返回其位置(不重要),所以用hashmap. 需要从任何位置删除,用linkedlist.最终二者结合,用linked hashm ... 
- ajax请求工具类
			ajax的get和post请求工具类: /** * 公共方法类 * * 使用 变量名=function()定义函数时,如果在变量名前加var,则这个变量变成局部变量 */var Common = ... 
- linux下一些常用系统命令
			查看系统打开的文件数 lsof|wc -l 查看当前目录下的文件数 find -type f | wc -l 查看某个目录下的文件数,注意这里/home包括其所有子目录 find /home -typ ... 
- geoserver中除了使用kml来查询数据以外,还可以使用csql或ecsql
			package com.geoserver; import java.io.IOException; import java.util.ArrayList; import java.util.Hash ... 
- 2018年UI设计趋势概览
			互联网产品的用户界面设计趋势是根据用户的不同需求而不断变化的.在仔细分析了过去几年用户界面设计的趋势和创新之后,我们可以发现其背后的一些规律,2018年UI界面设计的趋势如下. 渐变色 在过去的几年 ... 
- 2018.08.31 bzoj1426 收集邮票(期望dp)
			描述 有n种不同的邮票,皮皮想收集所有种类的邮票.唯一的收集方法是到同学凡凡那里购买,每次只能买一张,并且 买到的邮票究竟是n种邮票中的哪一种是等概率的,概率均为1/n.但是由于凡凡也很喜欢邮票,所以 ... 
