我试图根据第一个下级名单(包括国家)所选择的内容,把第二个下级名单(包括各州)列入。
我有一个称为“承诺”的控制者行动:
public JsonResult GetCounties(string id)
{
DBEntities dc = new DBEntities();
JsonResult result = new JsonResult();
var filteredDivisions = from div in dc.Divisions
where div.CountryID == 1 //id
select div;
result.Data = filteredDivisions.ToList();
return Json(result.Data, JsonRequestBehavior.AllowGet);
// return Json(new[] {
// new { Id = filteredDivisions.ToArray()[0].DivisionID, Value = filteredDivisions.ToArray()[0].DivisionName },
// new { Id = 2, Value = "value 2" },
// new { Id = 3, Value = "value 3" },
//}, JsonRequestBehavior.AllowGet);
}
通知评注部分。 这对我来说是值得称赞的,(我从各司名单上获得了第一笔价值,而另外两个则称为“价值2”和“价值3”。 我曾用过这段话来检验这一挫折,但这是我取得结果的唯一事情。 使用:
return Json(result.Data, JsonRequestBehavior.AllowGet);
不能取得任何意见。 当瓦解时,所有正确的价值观都存在,但是,它们并没有出现在意见方的名单上。 正如我所说的那样,我取得的唯一成果是使用所评论的法典(硬编码价值,当然这些价值还不够)。 我试图通过名单来播音,以便填满阵列,但没有任何工作,我只读匿名类型等错误,因此我无法再次确定。
这是我的支部法典:
$(function () {
$.getJSON( /Entity/GetCounties , function (result) {
var ddl = $( #DivisionsList );
ddl.empty();
$(result).each(function () {
$(document.createElement( option ))
.attr( value , this.Id)
.text(this.Value)
.appendTo(ddl);
});
});
});
The divisionslist is of course the dropdown with all the counties, which by using the non-commented return statement above, just returns unchanged, i.e. containing ALL of its values, and not just the ones that should come up depending on the selected country. so please HOW CAN I POPULATE AN ARRAY WITH THE FILTERED RESULTS SO THAT I CAN RETURN IT TO THE VIEW USING JSON? I want to use THIS code that I have posted, as it was THE ONLY ONE that ever worked. I just need to swap the hardcoded values with the right ones. that s where i m having trouble.
请帮助我。