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)工具,是为了解决“关系数据库”和“面向 ...
随机推荐
- Hammer.js——给bootstrap添加触屏功能
Hammer.js qq群号(html5技术交流):158677025 手机端演示二维码(或直接在手机中输入网址:http://lilinfeng.cncoder.me 浏览效果): 一.前言 移 ...
- boost x64 lib
libboost_atomic-vc150-mt-gd-x64-1_66.liblibboost_atomic-vc150-mt-s-x64-1_66.liblibboost_atomic-vc150 ...
- 3sum, 3sum closest
[抄题]: Given an array S of n integers, are there elements a, b, c in S such that a + b + c = 0? Find ...
- Collections.shuffle()源码分析
Java.util.Collections类下有一个静态的shuffle()方法,如下: 1)static void shuffle(List<?> list) 使用默认随机源对列表进行 ...
- web前端js 实现打印操作
转载来源:https://www.cnblogs.com/potatog/p/7412905.html 一.打印当前页面指定元素中的内容 方式一:直接使用window.print(); (1)首先获得 ...
- 手机端图片预览和缩放js
转至:http://blog.sina.com.cn/s/blog_c342e3090102vcxu.html 1.手机端的图片选择和预览 <input type="file" ...
- macos安装postman
安装命令 brew cask install postman brew 是从下载源码解压然后./configure && make install,同时会包含相关依存库.并自动配置 好 ...
- UI设计初学者如何避免走弯路?
对于初学UI设计的人而言,可能对UI具体是做什么,或者自己是否能顺利转行胜任这样的岗位存在一定的顾虑,今天我们就来重点说说UI是做什么的,以及想学UI到底要如何避免走弯路,快速的学成. 问题一:UI设 ...
- This page contains the following error
解决办法:将header头注释掉 header("content-type:text/xml; charset=UTF-8");
- C++对象拾遗
#include <iostream.h> #include <string.h> //using namespace std; class A { public: A ...