I want to pass value of selected input checkbox to controller using Jquery Ajax.
var selected = [];
$('.myCheckBox input:checked').each(function() {
selected.push($(this).attr('value'));
});
$.ajax({
url: '@Url.Action("test", "Display")',
type: 'GET',
data: {
MySelectdFile: selected
},
dataType: 'json',
traditional: true,
contentType: 'application/json',
success: function(data) {
alert("OK")
}
},
error: function(xhr, status, error) {
var err = eval("(" + xhr.responseText + ")");
alert(err.Message);
}, complete: function() {
$('#loading').hide();
}
});
[HttpGet]
public ActionResult test(string[] MySelectdFile)
{
foreach(string item in MySelectdFile)
{
//Do Something
}
}
When my Javascript array length is small ,everything works fine, but when my Javascript array length is big ,nothing happened.
contentType: 'application/json',
OR deletetraditional: true,
and change todata: JSON.stringify({ MySelectdFile: selected }),
ad it need to be a POST, not a GETtype: 'GET'
=> usetype: 'POST'
for large arrays. Also try removingcontentType: 'application/json'
because you want to pass an array.nothing happened
what about in the browser developer tools console? any errors/warnings/messages?