Here is my Action Mehtod
public JsonResult GetById(IEnumerable<Guid> idList)
{
//.....
}
And my JavaScript . I'm making an array of strings using li element's id property
var idArr = [];
var list = $("#ulApplications li");
$.each(list, function () { idArr.push($(this).attr("id")) });
$.ajax(
{
type: "GET",
url: "/rolemanagement/application/GetById/",
contentType: false,
datatype: "json",
data: { 'idList': idArr },
success:........
On my Action method I'm not getting any data.It seems I'm Missing something.
thanks
Change your ajax to
$.ajax({
type: "GET",
url: "/rolemanagement/application/GetById", // should use '@Url.Action(..)'
dataType: 'json',
contentType: "application/json; charset=utf-8",
data: JSON.stringify({ idList: idArr }), // stringify
success: ....
})
I tried out the below code which seems to be working fine,
$.ajax({
type: "GET",
url: "@Url.Action("GetById", new { area = "rolemanagement", controller = "application"})",
data: { idList: [{ a: 'a' }, { a: 'b' }] },
dataType: "json",
contentType: "application/json; charset=utf-8",
success: function (data) { console.log(data); },
error: function () { throw new Error("Error occurred."); }
});
which already given by @stephen where even stringify is not even required to send the data.
After searching on stackoverflow and other blogs. I found a solution which is working for me, although above given answers are closely correct but they didn't worked for me. Here is my answer
var IdList = {idList:idArr}
$.ajax(
{
type: "GET",
url: "/rolemanagement/application/GetById/",
contentType: false,
datatype: "json",
data: IdList,
traditional: true,
success:
function (data) {
alert(data);
},