我有点卡在这里。我有一个页面,通过使用 jQuery 加载显示三个不同的视图:与用户关联的所有类别的视图、所选类别中所有项目的图像和名称以及项目所有属性的完整详细视图选择。如何获取所选类别的 ID,而不是显示项目并与项目相同以显示完整详细信息。Ajax 不是问题,所以我认为。
当用户单击 this 中的 an<li>
以test <div>
检索该类别的项目时
$(document).ready(function() {
$('#test li').click(function() {
//get id of cat selected
$.ajax({
url: "",
type: "POST",
data: {//return all the item info},
success: function(data) {
//when returns display updated results
}
});
});
我认为这与单击项目时相同。但是如何为控制器编写查询。现在我只是显示所有:
//Item Controller
//two queries; one for displaying items when certain cat is selected and
// another to display full details when an item is selected
public ActionResult Partial(Item item)
{
//var query = from i in db.Items
// orderby i.dateAdded
// where i.user_id==4
// select i;
//var results = query;
var model = db.Items;
return PartialView("_Partial1", model);
}
public ActionResult PartialTwo() //pass in the catId??
{
var query = from d in db.Items
// how to get catID which is in the item table?
select d;
var results = query;
return PartialView("_FullInfoPartial", results);
}
//Category controller
//get the categories from
public ActionResult GetCats( Category cat)
{
var query = from c in db.Cats where c.user_id == 4 orderby c.catId select c;
var results = query;
return PartialView("_PartialGetCats", results);
}
我在正确的轨道上吗?