How pass int array from jquery ajax to asp.net mvc action
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
I have tried many stackoverflow posts, but I have always the same result.
The passed int array always null.
Pass array to mvc Action via AJAX
Here the asp.net mvc action which accept the int array of ids.
[HttpPost]
public ActionResult Downloads(int ids)
return RedirectToAction("Exports", ids);
This is the ajax call, which is send the values.
var url = '@Url.Action("Downloads")';
var values = [1,2,3];
$.ajax(
url: url,
type: 'POST',
dataType: "json",
contentType: 'application/json; charset=utf-8',
traditional: true,
data: JSON.stringify(ids: values )
);
I have no idea what I make wrong.
I have passed the ajax's date like a simple array: data: values
or without stringify, but the asp.net mvc never accept the int array. It seems the traditional
parameter of ajax
object does not do anything.
jquery asp.net-mvc asp.net-ajax
add a comment |
I have tried many stackoverflow posts, but I have always the same result.
The passed int array always null.
Pass array to mvc Action via AJAX
Here the asp.net mvc action which accept the int array of ids.
[HttpPost]
public ActionResult Downloads(int ids)
return RedirectToAction("Exports", ids);
This is the ajax call, which is send the values.
var url = '@Url.Action("Downloads")';
var values = [1,2,3];
$.ajax(
url: url,
type: 'POST',
dataType: "json",
contentType: 'application/json; charset=utf-8',
traditional: true,
data: JSON.stringify(ids: values )
);
I have no idea what I make wrong.
I have passed the ajax's date like a simple array: data: values
or without stringify, but the asp.net mvc never accept the int array. It seems the traditional
parameter of ajax
object does not do anything.
jquery asp.net-mvc asp.net-ajax
@RoryMcCrossan in this case I get a 'Invalid JSON primitive ids' error message. OK, content-type had to be removed too.
– Dabagab
Nov 15 '18 at 13:42
Glad you got it working, I added it as an answer for you below
– Rory McCrossan
Nov 15 '18 at 13:54
add a comment |
I have tried many stackoverflow posts, but I have always the same result.
The passed int array always null.
Pass array to mvc Action via AJAX
Here the asp.net mvc action which accept the int array of ids.
[HttpPost]
public ActionResult Downloads(int ids)
return RedirectToAction("Exports", ids);
This is the ajax call, which is send the values.
var url = '@Url.Action("Downloads")';
var values = [1,2,3];
$.ajax(
url: url,
type: 'POST',
dataType: "json",
contentType: 'application/json; charset=utf-8',
traditional: true,
data: JSON.stringify(ids: values )
);
I have no idea what I make wrong.
I have passed the ajax's date like a simple array: data: values
or without stringify, but the asp.net mvc never accept the int array. It seems the traditional
parameter of ajax
object does not do anything.
jquery asp.net-mvc asp.net-ajax
I have tried many stackoverflow posts, but I have always the same result.
The passed int array always null.
Pass array to mvc Action via AJAX
Here the asp.net mvc action which accept the int array of ids.
[HttpPost]
public ActionResult Downloads(int ids)
return RedirectToAction("Exports", ids);
This is the ajax call, which is send the values.
var url = '@Url.Action("Downloads")';
var values = [1,2,3];
$.ajax(
url: url,
type: 'POST',
dataType: "json",
contentType: 'application/json; charset=utf-8',
traditional: true,
data: JSON.stringify(ids: values )
);
I have no idea what I make wrong.
I have passed the ajax's date like a simple array: data: values
or without stringify, but the asp.net mvc never accept the int array. It seems the traditional
parameter of ajax
object does not do anything.
jquery asp.net-mvc asp.net-ajax
jquery asp.net-mvc asp.net-ajax
edited Nov 15 '18 at 13:23
Dabagab
asked Nov 15 '18 at 13:17
DabagabDabagab
4822817
4822817
@RoryMcCrossan in this case I get a 'Invalid JSON primitive ids' error message. OK, content-type had to be removed too.
– Dabagab
Nov 15 '18 at 13:42
Glad you got it working, I added it as an answer for you below
– Rory McCrossan
Nov 15 '18 at 13:54
add a comment |
@RoryMcCrossan in this case I get a 'Invalid JSON primitive ids' error message. OK, content-type had to be removed too.
– Dabagab
Nov 15 '18 at 13:42
Glad you got it working, I added it as an answer for you below
– Rory McCrossan
Nov 15 '18 at 13:54
@RoryMcCrossan in this case I get a 'Invalid JSON primitive ids' error message. OK, content-type had to be removed too.
– Dabagab
Nov 15 '18 at 13:42
@RoryMcCrossan in this case I get a 'Invalid JSON primitive ids' error message. OK, content-type had to be removed too.
– Dabagab
Nov 15 '18 at 13:42
Glad you got it working, I added it as an answer for you below
– Rory McCrossan
Nov 15 '18 at 13:54
Glad you got it working, I added it as an answer for you below
– Rory McCrossan
Nov 15 '18 at 13:54
add a comment |
2 Answers
2
active
oldest
votes
If you want to send values using traditional encoding then you shouldn't JSON encode the data you're sending. As such, remove the JSON.strigify()
call, as well as the contentType
. Try this:
$.ajax(
url: url,
type: 'POST',
dataType: "json",
traditional: true,
data: ids: values
);
add a comment |
Just remove JSON.stringify it will work.
[HttpPost]
public JsonResult Test(int ids)
return Json("Integers. " + ids);
//In Jquery please put this.
var PostData = ;
PostData.ids = [1, 2, 3, 5];
var ajaxOptions =
type: "POST",
url: '@Url.Action("Test", "Settings")',//Actionname, ControllerName
data: PostData,
dataType: "json",
success: function (result)
console.log(result);
,
error: function (result)
;
$.ajax(ajaxOptions);
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53320381%2fhow-pass-int-array-from-jquery-ajax-to-asp-net-mvc-action%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
If you want to send values using traditional encoding then you shouldn't JSON encode the data you're sending. As such, remove the JSON.strigify()
call, as well as the contentType
. Try this:
$.ajax(
url: url,
type: 'POST',
dataType: "json",
traditional: true,
data: ids: values
);
add a comment |
If you want to send values using traditional encoding then you shouldn't JSON encode the data you're sending. As such, remove the JSON.strigify()
call, as well as the contentType
. Try this:
$.ajax(
url: url,
type: 'POST',
dataType: "json",
traditional: true,
data: ids: values
);
add a comment |
If you want to send values using traditional encoding then you shouldn't JSON encode the data you're sending. As such, remove the JSON.strigify()
call, as well as the contentType
. Try this:
$.ajax(
url: url,
type: 'POST',
dataType: "json",
traditional: true,
data: ids: values
);
If you want to send values using traditional encoding then you shouldn't JSON encode the data you're sending. As such, remove the JSON.strigify()
call, as well as the contentType
. Try this:
$.ajax(
url: url,
type: 'POST',
dataType: "json",
traditional: true,
data: ids: values
);
answered Nov 15 '18 at 13:54
Rory McCrossanRory McCrossan
251k29217254
251k29217254
add a comment |
add a comment |
Just remove JSON.stringify it will work.
[HttpPost]
public JsonResult Test(int ids)
return Json("Integers. " + ids);
//In Jquery please put this.
var PostData = ;
PostData.ids = [1, 2, 3, 5];
var ajaxOptions =
type: "POST",
url: '@Url.Action("Test", "Settings")',//Actionname, ControllerName
data: PostData,
dataType: "json",
success: function (result)
console.log(result);
,
error: function (result)
;
$.ajax(ajaxOptions);
add a comment |
Just remove JSON.stringify it will work.
[HttpPost]
public JsonResult Test(int ids)
return Json("Integers. " + ids);
//In Jquery please put this.
var PostData = ;
PostData.ids = [1, 2, 3, 5];
var ajaxOptions =
type: "POST",
url: '@Url.Action("Test", "Settings")',//Actionname, ControllerName
data: PostData,
dataType: "json",
success: function (result)
console.log(result);
,
error: function (result)
;
$.ajax(ajaxOptions);
add a comment |
Just remove JSON.stringify it will work.
[HttpPost]
public JsonResult Test(int ids)
return Json("Integers. " + ids);
//In Jquery please put this.
var PostData = ;
PostData.ids = [1, 2, 3, 5];
var ajaxOptions =
type: "POST",
url: '@Url.Action("Test", "Settings")',//Actionname, ControllerName
data: PostData,
dataType: "json",
success: function (result)
console.log(result);
,
error: function (result)
;
$.ajax(ajaxOptions);
Just remove JSON.stringify it will work.
[HttpPost]
public JsonResult Test(int ids)
return Json("Integers. " + ids);
//In Jquery please put this.
var PostData = ;
PostData.ids = [1, 2, 3, 5];
var ajaxOptions =
type: "POST",
url: '@Url.Action("Test", "Settings")',//Actionname, ControllerName
data: PostData,
dataType: "json",
success: function (result)
console.log(result);
,
error: function (result)
;
$.ajax(ajaxOptions);
edited Nov 15 '18 at 13:37
answered Nov 15 '18 at 13:28
Negi RoxNegi Rox
1,9351512
1,9351512
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53320381%2fhow-pass-int-array-from-jquery-ajax-to-asp-net-mvc-action%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
@RoryMcCrossan in this case I get a 'Invalid JSON primitive ids' error message. OK, content-type had to be removed too.
– Dabagab
Nov 15 '18 at 13:42
Glad you got it working, I added it as an answer for you below
– Rory McCrossan
Nov 15 '18 at 13:54