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)工具,是为了解决“关系数据库”和“面向 ...
随机推荐
- Island Transport
Island Transport http://acm.hdu.edu.cn/showproblem.php?pid=4280 Time Limit: 20000/10000 MS (Java/Oth ...
- Sql求和异常——对象不能从 DBNull 转换为其他类型
做项目遇到一个以前没遇到的问题,就是要计算一个用户消费总额, 关键代码如下: string sql = "select sum(Tmoney) from [order] where uid= ...
- 对象之int介绍
#Auther Bob #--*--conding:utf-8 --*-- #创建两个int的对象,age1和age2 age1 = 10 age2 = int(1) #查看对象的类 print(ty ...
- mockito使用
mockito学习资料: http://docs.mockito.googlecode.com/hg/org/mockito/Mockito.html http://blog.csdn.net/sdy ...
- Nginx 分析access日志文件
Nginx Access Log日志统计分析常用命令 IP相关统计 统计IP访问量 awk '{print $1}' access.log | sort -n | uniq | wc -l 查看某一时 ...
- Laravel 上使用 phpexcel的两种方式
原创 2017年06月24日 20:24:31 1229 文章采集与网上 方式1.使用原生的phpexcel , http://blog.csdn.net/CSwfe/article/details/ ...
- oracle去重试验
http://blog.csdn.net/lunajiao/article/details/76014488
- mvc的表单发送ajax请求,太强大了!!!!
- centos6.5 设置ssh无密码登录
:关闭防火墙 vim /etc/selinux/config 把SELINUX=enforcing修改为SELINUX=disabled A机器root连接B机器root用户 (root用户登录) ...
- Eclipse 中 Could not find *.apk的解决方案
Eclipse 中 Could not find *.apk的解决方案 有时候debug的时候出现Could not find *.apk 特别是导入别人的例子的时候 1.选择properties-& ...