forhamid
شنبه 24 خرداد 1393, 21:42 عصر
سلام من تو برنامه ام دو تا drop down list گذاشتم که هر دوتای اونها ابتدا با ViewBag که از سرور اومده پر میشوند با تغییر لیست اول به صورت ajax محتویات لیست دوم از کنترلر گرفته میشه. تا اینجا برنامه درست کار میکنه اما زمانی که برنامه رو میخوام بفرستم سمت سرور این خطا رو بهم میده
The ViewData item that has the key 'Week' is of type 'System.Int32' but must be of type 'IEnumerable<SelectListItem>'
کد داخل view
@DropDownList("Week",@ViewBag.Week,"-- select week --",new {id="rdbWeeks"})
@DropDownList("Game",@ViewBag.Game,"-- select Game--",new {id="rdbGame"})
کد jQuery
<script> $('#rdbWeek').change(function () {
jQuery.getJSON('@Url.Action("GetGames")', { id: $(this).attr('value') }, function (data) {
$('#rdbGame').empty();
var optionSelectGame = $('<option></option>').attr("value", "selectGame").text("انتخاب بازی");
$('#rdbGame').append(optionSelectGame);
jQuery.each(data, function (i) {
var option = $('<option></option>').attr("value", data[i].Id).text(data[i].Game);
$("#rdbGame").append(option);
});
});
});
</script>
The ViewData item that has the key 'Week' is of type 'System.Int32' but must be of type 'IEnumerable<SelectListItem>'
کد داخل view
@DropDownList("Week",@ViewBag.Week,"-- select week --",new {id="rdbWeeks"})
@DropDownList("Game",@ViewBag.Game,"-- select Game--",new {id="rdbGame"})
کد jQuery
<script> $('#rdbWeek').change(function () {
jQuery.getJSON('@Url.Action("GetGames")', { id: $(this).attr('value') }, function (data) {
$('#rdbGame').empty();
var optionSelectGame = $('<option></option>').attr("value", "selectGame").text("انتخاب بازی");
$('#rdbGame').append(optionSelectGame);
jQuery.each(data, function (i) {
var option = $('<option></option>').attr("value", data[i].Id).text(data[i].Game);
$("#rdbGame").append(option);
});
});
});
</script>