我使用此代碼來獲取檢查日期,但它沒有得到int []值。哪裏錯了。如何使用int數組加載partialview的視圖在asp.net中使用jquery mvc
查看頁:
function displayCheckedPersons() {
var $checkedRecords = new Array();
var j;
j = 0;
var nodes = $("#PersonTree").jstree("get_checked",null,true);
$.each(nodes, function (i, element) {
if ($(element).attr("ifPerson") == "Y") {
$checkedRecords[j] = $(element).attr("id");
j = j + 1;
};
});
if ($checkedRecords.length < 1) {
alert('Please Select Persons first.');
return;
}
$('#result').load('<%= Url.Action("DisplayCheckedPersons", "Scheduling") %>',$checkedRecords);
}
</script>
操作代碼:
public ActionResult DisplayCheckedPersons(int[] checkedRecords)
{
AttendMSDataContext db = new AttendMSDataContext();
checkedRecords = checkedRecords ?? new int[] { };
return PartialView("CheckedPersons", db.Persons.Where(o => checkedRecords.Contains(o.id)));
}
編輯戴: 我用$ AJAX張貼陣列,像這樣:
$.ajax({
type: "POST",
url: "<%= Url.Action("DisplayCheckedPersons", "Scheduling") %>",
data: { checkedRecords: checkedPersons },
dataType: "html",
success: function (request) { $("#result").html(request); },
traditional: true
});
我不認爲它的原因,但你不需要使用checkedRecords的$盈是。 – Henry