我有一个PartialView,它显示表中的项目。我想用一些标准来过滤它们。我的观点:在部分视图中过滤
@model Bike_Store.Models.PartsViewModel
<form method="get">
<div>
<label>Category: </label>
@Html.DropDownList("categorie", Model.Categories as SelectList,
htmlAttributes: new { @class="form-control"})
<label>Brand: </label>
@Html.DropDownList("brand", Model.Brands as SelectList,
htmlAttributes: new { @class="form-control" })
<input type="submit" value="Filter" />
</div>
</form>
<table>...</table>
我的控制器:
[HttpGet]
public ActionResult PartsPartial(int? categorie, int? brand)
{
IQueryable<bs_parts> parts = _db.bs_parts.Include(p => p.bs_categories);
if (categorie != null && categorie != 0)
{
parts = parts.Where(p => p.parts_category_id == categorie);
}
if (brand != null && brand != 0)
{
parts = parts.Where(p => p.parts_brand_id == brand);
}
List<bs_categories> categoriesList = _db.bs_categories.ToList();
List<bs_brands> brandsList = _db.bs_brands.ToList();
PartsViewModel pvm = new PartsViewModel
{
Parts = parts.ToList(),
Categories = new SelectList(categoriesList, "categories_id", "categories_name"),
Brands = new SelectList(brandsList, "brands_id", "brands_name")
};
return PartialView(pvm);
}
过滤这种方式正常工作与正常View
。但是,当我尝试与Partial View
一样做时,它不起作用,页面只是重新加载。我把break point
检查,如果我的Get方法工作,当我按Filter
按钮,我注意到它不。问题是什么?
我打电话Partial View
从菜单中有:
@Ajax.ActionLink(
"Parts",
"PartsPartial",
new
{
value1 = 1
},
new AjaxOptions
{
HttpMethod = "GET",
InsertionMode = InsertionMode.Replace,
UpdateTargetId = "content"
}, new { @class = "button" }
)
<div class="content" id="content">
</div>
@ Html.Partial()或@ Html.RenderPartial不做任何con troller调用,并且几乎不能用你的模型呈现html视图。 考虑使用Html.RenderAction代替 – Igor