Controller:
RingRepository ringRepository = new RingRepository();
public ActionResult Index(string sort, string SearchString)
{
ViewBag.NameSortParm = string.IsNullOrEmpty(sort) ? "Name desc" : "";
var list = ringRepository.GetAll();
//search RingName by searchParm
if (!string.IsNullOrEmpty(SearchString))
{
list = list.Where(r => r.ringName.ToUpper().Contains(SearchString.ToUpper()));
}
switch (sort)
{
case "Name desc":
list = list.OrderBy(r => r.ringName);
break;
default:
list = list.OrderByDescending(r => r.ringName);
break;
}
return View(list);
}
View:
@model IEnumerable<LisknoveShop.Models.Ring>
<p>
@using (Html.BeginForm())
{
<p>
Find by RingName: @Html.TextBox("SearchString")
<input type="submit" value="Search" /></p>
}</p>
<table>
<tr>
<th>@Html.ActionLink("RingName", "Index", "Ring", new { area = "Admin", sort = ViewBag.NameSortParm }, null)
</th>
<th>
ringImage
</th>
<th>
price
</th>
<th>
genreId
</th>
<th>
materialId
</th>
<th>
</th>
</tr>
@foreach (var item in Model)
{
<tr>
<td>
@Html.DisplayFor(modelItem => item.ringName)
</td>
<td>
@Html.DisplayFor(modelItem => item.ringImage)
</td>
<td>
@Html.DisplayFor(modelItem => item.price)
</td>
<td>
@Html.DisplayFor(modelItem => item.genreId)
</td>
<td>
@Html.DisplayFor(modelItem => item.materialId)
</td>
<td>
@Html.ActionLink("Edit", "Edit", new { id = item.ringId }) |
@Html.ActionLink("Details", "Details", new { id = item.ringId }) |
@Html.ActionLink("Delete", "Delete", new { id = item.ringId })
</td>
</tr>
}
</table>
MVC 3.0 排序 查询
转载![](https://ucenter.51cto.com/images/noavatar_middle.gif)
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
排序算法之计数排序的优化
排序算法之计数排序的优化
数组 计数排序 最小值 -
MVC 3.0 搞笑网站
Suhow.com致力于打造网络最精选搞笑站点,技术支持ASP.NET MVC 3.0 + EF 4.0,欢迎广大网友登临,在研究技术之余,看看搞笑,调整心情,快乐每一天。
.NET IT C# WEB MVC Jquery