在orchard中获取数据实体
public List<nonoRecord> Get()
{
return this._nonoRecordRepository.Table.ToList();
}
public nonoRecord Get(int id)
{
return this._nonoRecordRepository.Fetch(c => c.Id == id).FirstOrDefault();
}
public nonoRecord Get(string name)
{
return this._nonoRecordRepository.Fetch(c => c.Name == name).FirstOrDefault();
}
public List<nonoRecord> mohuGet(string name)
{
return this._nonoRecordRepository.Fetch(c => c.Name.Contains(name)).ToList();
}
mvc中 lndex页面加上一些筛选功能。通过给Index传递参数来实现筛选,在页面添加一个selectbox来筛选Genre字段,把MovieController的方法改成:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
public
ViewResult Index(
string
movieGenre)
{
var
genre = (
from
s
in
db.Movies
orderby
s.Genre
select
s.Genre).Distinct();
ViewBag.MovieGenre =
new
SelectList(genre);
//给前台准备下拉列表的数据。
if
(!
string
.IsNullOrEmpty(movieGenre))
{
//筛选
var
movies =
from
s
in
db.Movies
where
s.Genre == movieGenre
select
s;
return
View(movies);
}
return
View(db.Movies.ToList());
}
|
在View页面,添加一个Form,里面放上一个选择框和一个按钮,代码如下:
1
2
3
4
|
@
using
(Html.BeginForm(
"Index"
,
"Movie"
, FormMethod.Get))
{
<p>Genre: @Html.DropDownList(
"MovieGenre"
,
"全部"
) <input type=
"submit"
value=
"筛选"
/></p>
}
|
1
|
|
效果如下: