选择类别后,我似乎无法理解如何更新项目的 div。我已经走了这么远,现在很困惑。如何将视图中的值获取到控制器中以进行查询?
//get <li> clicked and display the items in that category
$(document).ready(function() {
$('#test li').click(function() {
var selector = "input[name='" + $(this).id + "value']";
var catID = $(selector).val();
$.ajax({
url: "...",
type: "get",
data: {//return all the item info},
success: function(data) {
//update div contents here?
}
});
});
});
部分将根据单击的类别进行更新
@foreach (var item in Model)
{
<ul>
<li>@item.item_name</li>
<li><input type="hidden" class="item_id" value="@item.ID" /></li>
</ul>
}
控制器
public ActionResult PartialTwo( int id)//how to pass category id?
{
var query = from d in db.Items
where d.catId==id
orderby d.dateAdded
select d;
var results = query;
return PartialView("_FullInfoPartial", results);
//returns items in the clicked category
}