首先先说排序

非常的简单

代码如下

 //创建视图
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 学习笔记(三),排序加查找的更多相关文章

  1. ASP.NET MVC 学习笔记-2.Razor语法 ASP.NET MVC 学习笔记-1.ASP.NET MVC 基础 反射的具体应用 策略模式的具体应用 责任链模式的具体应用 ServiceStack.Redis订阅发布服务的调用 C#读取XML文件的基类实现

    ASP.NET MVC 学习笔记-2.Razor语法   1.         表达式 表达式必须跟在“@”符号之后, 2.         代码块 代码块必须位于“@{}”中,并且每行代码必须以“: ...

  2. ASP.NET MVC学习笔记-----Filter2

    ASP.NET MVC学习笔记-----Filter(2) 接上篇ASP.NET MVC学习笔记-----Filter(1) Action Filter Action Filter可以基于任何目的使用 ...

  3. ASP.NET MVC学习笔记-----Filter

    ASP.NET MVC学习笔记-----Filter(1) Filter类型 接口 MVC的默认实现 Description Authorization IAuthorizationFilter Au ...

  4. ASP.NET MVC学习笔记-----Filter(2)

    接上篇ASP.NET MVC学习笔记-----Filter(1) Action Filter Action Filter可以基于任何目的使用,它需要实现IActionFilter接口: public ...

  5. 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 ...

  6. ASP.NET MVC学习笔记 第三天

    布局: 如果不使用布局页,需要将Layout属性设置为null. @{     Layout = null; } 使用默认布局页: 使用Add View对话框,选择使用布局页(是布局页的名称文本框为空 ...

  7. ASP.NET MVC学习笔记(二)笔记

    接下来我们一起了解ASP.NET MVC的最重要的核心技术,了解ASP.NET MVC的开发框架,生命周期,技术细节. 一.Routing与ASP.NET MVC生命周期 1.Routing——网址路 ...

  8. ASP.NET MVC 学习笔记(1)

    从头开始系统地学习ASP.NET MVC 为什么要学习ASP.NET MVC?原因很多,可以先来看一下最早的ASP.NET WebForm的一些缺点: 传说中面试经常要问到的ASP.NET WebFo ...

  9. ASP.NET MVC 学习笔记 1

    1. 什么是ASP.Net MVC ASP.Net MVC是一种开发Web应用程序的工具(is a web application development framework),采用Model-Vie ...

  10. 【ASP.NET MVC 学习笔记】- 07 使用 Entity Framework

    本文参考:http://www.cnblogs.com/willick/p/3304534.html 1.ORM(Object Relation Mapping)工具,是为了解决“关系数据库”和“面向 ...

随机推荐

  1. .NET中的文件IO操作实例

    1.写入文件代码: //1.1 生成文件名和设置文件物理路径 Random random = new Random(DateTime.Now.Millisecond); ); string Physi ...

  2. ViewPager 带动画的欢迎界面

    一般APP进去之后都会有几张图片来导航,这里就学习怎么在这张图片切换的时候添加切换动画效果 先看布局文件 activity_main.layout <?xml version="1.0 ...

  3. Golang之go 命令用法

    Go 命令 Go 命令 Go语言自带有一套完整的命令操作工具,你可以通过在命令行中执行go来查看它们: 图1.3 Go命令显示详细的信息 这些命令对于我们平时编写的代码非常有用,接下来就让我们了解一些 ...

  4. CreateThread

    CreateThread(NULL,0,ReportResultThread,this,0,&g_dwThreadId) 2. 参数说明: 第一个参数 lpThreadAttributes 表 ...

  5. AJAX 请求中多出了一次 OPTIONS 请求 导致 Laravel 中间件无法对 Header 传入的 Token 无法获取

    背景知识: 我们会发现,在很多post,put,delete等请求之前,会有一次options请求.本文主要是来讨论一下这是什么原因引起的. 根本原因就是,W3C规范这样要求了!在跨域请求中,分为简单 ...

  6. sqoop 安装使用

    安装配置: 1.将sqoop-1.4.4.tar.gz 上传到/usr/local/ 2.解压 tar -zxvf sqoop-1.4.4.tar.gz 3.配置 vim /etc/profile 在 ...

  7. Directory /usr/local/hadoop/tmp/tmp/hadoop-root/dfs/name is in an inconsistent state: storage directory does not exist or is not accessible

    解决方法: <property> <name>hadoop.tmp.dir</name> <value>/usr/local/hadoop/tmp< ...

  8. 2018.06.29 NOIP模拟 Minimum(最小生成树)

    Minimum 题目背景 SOURCE:NOIP2015-SHY-2 题目描述 给出一幅由 n 个点 m 条边构成的无向带权图. 其中有些点是黑点,另外点是白点. 现在每个白点都要与他距离最近的所有黑 ...

  9. 【Unity】2.1 初识Unity编辑器

    分类:Unity.C#.VS2015 创建日期:2016-03-26 一.简介 本节要点:了解Unity编辑器的菜单和视图界面,以及最基本的操作,这是入门的最基础部分,必须掌握. 二.启动界面 双击桌 ...

  10. IntelliJ IDEA 2017版 spring-boot加载jsp配置详解(详细图文实例)

    一.创建项目 (File--->New-->Project) 2.项目配置内容 3.选择配置项目的Group包名,Artifact项目名称 4.选择项目类型为web类型 5.创建成功,点击 ...