I'm new in this Asp.Net MVC. How to pass 2d Array from ajax request to controller. I'm passing this array to parameter in my Controller but it gives me a null value. Here's my code:
View script
$("#UpdatePosition").click(function () {
var positions = [];
$('.updated').each(function () {
positions.push([$(this).attr('data-index'), $(this).attr('data-position')]);
$(this).removeClass('updated');
});
$.ajax({
type: 'POST',
cache: false,
dataType: 'JSON',
async: false,
traditional: true,
//contentType: 'application/json; charset=UTF-8',
url: '@Url.Action("UpdateCategoryGroupPosition", "Admin")',
data: { data: positions }, //Sample position data = [1,1], [2,2], [3,3]
success: function (result) {
if (result == true) {
alert("sucess")
}else{
alert("failed")
}
}, error: function (xhr, status, error) {
alert(error);
}
});
});
in Controller
[HttpPost]
public JsonResult UpdateCategoryGroupPosition(string[][] data)
{
var result = false;
try
{
if (data!= null)
{
}
result = true;
}
}
catch (Exception ex)
{
throw ex;
}
return Json(result, JsonRequestBehavior.AllowGet);
}
Thanks for helping me.
