问题描述:在ASP.NET MVC 中实现 下拉框触发查询。
使用技术:Linq to sql
已实现功能:
1。Select 已经可以获取分类值及ID。
2。使用强类型实现数据分页。
待解决问题:
1。当选择“请选择分类”分类时,根据所选择的分类ID进行查询后重新加载显示页面数据
注意:
1。加载数据后保留原有分页功能。
2。TEquipmentComponent是表名。我使用的是linq to sql
View视图代码(使用强类型)
01 |
<select id="SelectTypeASingle" name="SelectTypeA"> |
02 |
<option>请选择分类</option> |
03 |
</select> |
04 |
<table> |
05 |
<thead> |
06 |
<tr> |
07 |
<th>配件编号</th> |
08 |
<th>配件名称</th> |
09 |
<th>配件类型</th> |
10 |
<th>库存(NA)</th> |
11 |
</tr> |
12 |
</thead> |
13 |
<tbody> |
14 |
<% foreach(TEquipmentComponent n in(IEnumerable) ViewData.Model) { %> |
15 |
<tr> |
16 |
<td><%:n.ComponentID %></td> |
17 |
<td><%:Html.ActionLink(n.ComponentName,"","")%></td> |
18 |
<td><%:n.TEquipmentComponentTypeC.EquipmentTypeCName%></td> |
19 |
<td><%:n.CompanyTotal %></td> |
20 |
</tr> |
21 |
<% } %> |
22 |
</tbody> |
23 |
</table> |
24 |
<div class="mike_mvc_pager"> |
25 |
<%=Html.MikePager(ViewData.Model as PagedList<TEquipmentComponent>)%> |
26 |
</div> |
Controller代码:
01 |
public ActionResult LoadComponentList(int? pageIndex) |
02 |
{ |
03 |
//定义分页大小 |
04 |
int pagesize = 10; |
05 |
IQueryable<TEquipmentComponent> componentlist; |
06 |
componentlist = from c in db.TEquipmentComponents |
07 |
where c.ComponentFlag == 1 |
08 |
orderby c.ComponentID descending |
09 |
select c; |
10 |
try |
11 |
{ |
12 |
//分页 |
13 |
PagedList<TEquipmentComponent> _componentlist = componentlist.ToPagedList(pageIndex, pagesize); |
14 |
return View(_componentlist); |
15 |
} |
16 |
catch (Exception ex) |
17 |
{ |
18 |
SystemErrorLog.CreateErrorLog("加载零配件数据失败:" + ex.Message); |
19 |
} |
20 |
return View(); |
21 |
} |
1 |
谢谢帮助解答!本人新手。 |
componentlist = from c in db.TEquipmentComponents
where c.ComponentFlag == 1
orderby c.ComponentID descending
select c;
where后面再加一个条件就可以了。where c.ComponentFlag == 1 and c.guid=guid.parlse(下拉框.selcteitem.value)