我对jQuery和图表非常陌生。这是我的脚本,它工作正常。它给了我用户选择的复选框的ID。我在我的控制器中有一个图表操作,它也可以正常工作,但它会使用我所有的值创建图表。我希望它根据脚本中选定的值创建图表。我不知道如何将选定的值传递给我的控制器。从JavaScript MVC控制器传递数据
var checkboxes = $("input[type='checkbox']");
$(function()
{
function getValueUsingClass() {
/* declare an checkbox array */
var chkArray = [];
/* look for all checkboes that have a class 'chk' attached to it and check if it was checked */
$(".chk:checked").each(function() {
chkArray.push($(this).val());
});
/* we join the array separated by the comma */
var selected = chkArray.join(",") + ",";
/* check if there is selected checkboxes, by default the length is 1 as it contains one single comma */
if (selected.length > 1)
{
alert("You have selected " + selected);
}
else
{
alert("Please check at least one of the checkbox");
}
}
$("#Charter").click(function() {
getValueUsingClass();
});
});
您的操作方法未采用任何参数。你想发送什么数据? – Shyju
我试图发送arrar chkArray中的值到我的控制器中的我的Charter Action – lagfvu
迭代等Instaed,更简单的是通过提取选中的复选框$('input [type =“checkbox”]:checked')。为了沟通,您可以使用ajax并在您的控制器中返回JSON。然后在highcharts创建使用$ .getJSON()和加载数据/选项 –