我在Web应用程序中创建表单,我根据用户选择使用ajax过滤数据并使用jason获取数据都运行良好但是当我想获取嵌套数据时会出现问题 我从表BankPlans值和每个bankid获得我从其他表获得所有必需的文档我试图让他们在杰森的一个方法中选择
new { Percent = r.percent, Reqdocs = docs });
并在每个reqDosc的ajax循环结果中将它们放入列表中
Ajax:
var addressData = JSON.stringify(jsonData);
$.ajax({
url: '/Getyourcar/GetPlans',
type: "POST",
dataType: "json",
contentType: "application/json; charset=utf-8",
data: addressData,
success: function (result) {
$("#carousel").empty();
for (i = 0; i < result.length; i++) {
$("#carousel").append("<div class='carousel-feature'><div class='content'><h3>الفائدة السنوية</h3><div class='rate'> " + result[i].percent + " </div><div class='feature_cnt'> <ul></ul> </div> <a href='javascript:void(0)' class='check' title=" + result[i].percent + ">اختر</a></div><img class='carousel-image' alt='Image Caption' src='/images/1px.png'></div>");
$('input[name="planid"]').val(result[i].planid);
getDocs();
}
},
error: function (result) {
}
});
}
var getDocs = function () {
var jsonData = {
"Planid": $("#planid").val(),
};
var addressData = JSON.stringify(jsonData);
$.ajax({
url: '/Getyourcar/Getdocs',
type: "POST",
dataType: "json",
contentType: "application/json; charset=utf-8",
data: addressData,
success: function (result) {
$("#carousel .feature_cnt ul").empty();
for (i = 0; i < result.length; i++) {
$("#carousel .feature_cnt ul").append("<li>" + result[i].plan + " </li>");
}
},
error: function (result) {
alert("failed");
}
});
控制器:
public ActionResult GetPlans(string BankName = "", string Period = "", string customergrade = "")
{
int bankid = db.Banks.Where(b => b.Name.Contains(BankName) || BankName == "").FirstOrDefault().Id;
int yearid = db.Yearss.Where(b => b.Name.Contains(Period) || Period == "").FirstOrDefault().Id;
int cusgradeid = db.CustomerGrades.Where(c => c.Name.Contains(customergrade) || customergrade == "").FirstOrDefault().Id;
var Bankplanid = db.BankPlanss.Where(b => (b.BankId == bankid) &&
(b.CustomerGradeId == cusgradeid))
.Select(r => new { cusgrade = cusgradeid, bankid = r.BankId, percent = r.Percent, planid = r.Id });
return Json(Bankplanid, JsonRequestBehavior.AllowGet);
}
public ActionResult Getdocs(int Planid = 0)
{
var plans = db.BankPlansReqDocs.Where(b => b.BankPlansId == Planid)
.Select(r => new { plan = r.RequiredDocs.Name });
return Json(plans, JsonRequestBehavior.AllowGet);
}
当在VS中使用调试时,Getdocs方法在第一次调用两次时参数中的Planid获取值,当按F10时,同一行再次调用下一个值并返回最后一个值的Jason。 / p>
请帮助,提前致谢。
答案 0 :(得分:0)
通过将所有文档作为以(,)分隔的字符串和列表中的所有ID传递来解决问题。