我有第一个循环,它在SelectList中显示数据,如下所示
<select id="Select1" size="10" name="SeriesID" class="form-control" data-live-search="true">
@foreach (var series in Model)
{
<option value="@series.SeriesID">@series.Series_Title</option>
}
</select>
现在我想从SelectList中的Select1中选择数据来获取@ series.SeriesID并传递 第二个循环中的那个值。
你会注意到在第二个循环(Select2)中我有手动输入ID 163,我想从第一个循环中传递163个@serct.SeriesID insted
<select id="Select2" size="10" name="SeasonID" class="form-control">
@foreach (var series in Model.Select(s=>s.Seasons))
{
foreach (var season in series.Where(s => s.SeriesID == 163))
{
<option value="@season.SeasonID">@season.Name</option>
}
}
</select>
答案 0 :(得分:0)
我设法找到了解决方案。
HttpGet]
public JsonResult GetSeason(int ID)
{
db.Configuration.ProxyCreationEnabled = false;
List<Season> season = db.Seasons.Where(s => s.SeriesID == ID).ToList();
return Json(season, JsonRequestBehavior.AllowGet);
}
$(function () {
$("#Select1").change(function () {
var ID = $("#Select1").val();
var zahev = $.get("/Serije/GetSeason/" + ID);
zahev.done(function (rezultat) {
$("#Select2").empty();
$.each(rezultat, function (index, row) {
$("#Select2").append("<option value = '"+ row.SeasonID +"'>"+ row.Name +"</option>");
})
});
});
});