Pass array of json objects to MVC 5 Action via JQuery AJAX, and the Action Parameter has records, but no data
I've tried solutions from similar questions, but I'm not having any success.
I'm passing a jQuery object of array rows to anMVC5 controller action.
If I specify the action parameter as string, then it gets to ation, but the param is null.
If I specify the param as a List and the jquery array structure matches the List structure, I get a server 500 error.
I've tried the datatype, the content type etc as per other posts on SO, but no success.
Can someone please help.
List structure is:
public class ActionPermission2
{
public int ID = 0;
public int FKMenuID = 0;
public string ActionName = "";
public string Allowed = "";
public int PermissionType = 0;
public int PermissionTypeID = 0;
}
Action Method's attempted (one as a List of the actionPermissions and another as a string array :
public ActionResult UpdateModel2(List<ActionPermission2> menuPermissionsModel)
{
return Json(true, JsonRequestBehavior.AllowGet);
}
public ActionResult UpdateModelSA(string menuPermissionsModel)
{
return Json(true, JsonRequestBehavior.AllowGet);
}
JS and jQuery:
$('input[type=checkbox]').each(function ()
{
var datarow = {
"ID": pId,
"FKMenuID": mId,
"ActionName": actionName,
"Allowed": checked,
"PermissionType": "",
"PermissionTypeID": ptId
};
jsonObj.push(datarow);
}
});
$.ajax({
type: "POST",
//url: "@Url.Action("Update")", //string menuPermissionsModel
url: "@Url.Action("UpdateModel2")", //List<ActionPermission2> menuPermissionsModel
//url: "@Url.Action("UpdateModelSA2")", //List<string> menuPermissionsModel
data: JSON.stringify({ 'menuPermissionsModel': jArray }),
traditional: true,
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (data)
{
alert('data: ' + data);
},
error: function (data)
{
alert("error");
console.log(data);
}
});
when directing the ajax call to the List param,..there are all the records, but they all show the default values as per the class in which it is constructed,..i.e. no data.
Edit2: Data ex console.log.
[{"ID":"0","FKMenuID":"38","ActionName":"Read","Allowed":false,"PermissionType":"","PermissionTypeID":"0"},
{"ID":"0","FKMenuID":"38","ActionName":"Create","Allowed":false,"PermissionType":"","PermissionTypeID":"0"},
{"ID":"0","FKMenuID":"38","ActionName":"Update","Allowed":false,"PermissionType":"","PermissionTypeID":"0"},
{"ID":"0","FKMenuID":"38","ActionName":"Delete","Allowed":false,"PermissionType":"","PermissionTypeID":"0"},
{"ID":"0","FKMenuID":"65","ActionName":"Read","Allowed":false,"PermissionType":"","PermissionTypeID":"0"},
{"ID":"0","FKMenuID":"65","ActionName":"Create","Allowed":false,"PermissionType":"","PermissionTypeID":"0"},
{"ID":"0","FKMenuID":"50","ActionName":"Delete","Allowed":false,"PermissionType":"","PermissionTypeID":"0"},
{"ID":"0","FKMenuID":"67","ActionName":"Read","Allowed":false,"PermissionType":"","PermissionTypeID":"0"},
{"ID":"0","FKMenuID":"67","ActionName":"Create","Allowed":false,"PermissionType":"","PermissionTypeID":"0"},
{"ID":"0","FKMenuID":"67","ActionName":"Update","Allowed":false,"PermissionType":"","PermissionTypeID":"0"},
{"ID":"0","FKMenuID":"67","ActionName":"Delete","Allowed":false,"PermissionType":"","PermissionTypeID":"0"}]
jquery arrays json ajax asp.net-mvc-5
|
show 7 more comments
I've tried solutions from similar questions, but I'm not having any success.
I'm passing a jQuery object of array rows to anMVC5 controller action.
If I specify the action parameter as string, then it gets to ation, but the param is null.
If I specify the param as a List and the jquery array structure matches the List structure, I get a server 500 error.
I've tried the datatype, the content type etc as per other posts on SO, but no success.
Can someone please help.
List structure is:
public class ActionPermission2
{
public int ID = 0;
public int FKMenuID = 0;
public string ActionName = "";
public string Allowed = "";
public int PermissionType = 0;
public int PermissionTypeID = 0;
}
Action Method's attempted (one as a List of the actionPermissions and another as a string array :
public ActionResult UpdateModel2(List<ActionPermission2> menuPermissionsModel)
{
return Json(true, JsonRequestBehavior.AllowGet);
}
public ActionResult UpdateModelSA(string menuPermissionsModel)
{
return Json(true, JsonRequestBehavior.AllowGet);
}
JS and jQuery:
$('input[type=checkbox]').each(function ()
{
var datarow = {
"ID": pId,
"FKMenuID": mId,
"ActionName": actionName,
"Allowed": checked,
"PermissionType": "",
"PermissionTypeID": ptId
};
jsonObj.push(datarow);
}
});
$.ajax({
type: "POST",
//url: "@Url.Action("Update")", //string menuPermissionsModel
url: "@Url.Action("UpdateModel2")", //List<ActionPermission2> menuPermissionsModel
//url: "@Url.Action("UpdateModelSA2")", //List<string> menuPermissionsModel
data: JSON.stringify({ 'menuPermissionsModel': jArray }),
traditional: true,
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (data)
{
alert('data: ' + data);
},
error: function (data)
{
alert("error");
console.log(data);
}
});
when directing the ajax call to the List param,..there are all the records, but they all show the default values as per the class in which it is constructed,..i.e. no data.
Edit2: Data ex console.log.
[{"ID":"0","FKMenuID":"38","ActionName":"Read","Allowed":false,"PermissionType":"","PermissionTypeID":"0"},
{"ID":"0","FKMenuID":"38","ActionName":"Create","Allowed":false,"PermissionType":"","PermissionTypeID":"0"},
{"ID":"0","FKMenuID":"38","ActionName":"Update","Allowed":false,"PermissionType":"","PermissionTypeID":"0"},
{"ID":"0","FKMenuID":"38","ActionName":"Delete","Allowed":false,"PermissionType":"","PermissionTypeID":"0"},
{"ID":"0","FKMenuID":"65","ActionName":"Read","Allowed":false,"PermissionType":"","PermissionTypeID":"0"},
{"ID":"0","FKMenuID":"65","ActionName":"Create","Allowed":false,"PermissionType":"","PermissionTypeID":"0"},
{"ID":"0","FKMenuID":"50","ActionName":"Delete","Allowed":false,"PermissionType":"","PermissionTypeID":"0"},
{"ID":"0","FKMenuID":"67","ActionName":"Read","Allowed":false,"PermissionType":"","PermissionTypeID":"0"},
{"ID":"0","FKMenuID":"67","ActionName":"Create","Allowed":false,"PermissionType":"","PermissionTypeID":"0"},
{"ID":"0","FKMenuID":"67","ActionName":"Update","Allowed":false,"PermissionType":"","PermissionTypeID":"0"},
{"ID":"0","FKMenuID":"67","ActionName":"Delete","Allowed":false,"PermissionType":"","PermissionTypeID":"0"}]
jquery arrays json ajax asp.net-mvc-5
1
"I get a server 500 error."....so, that means the server crashed with an exception. The first thing you need to do before asking a question is find out what the exception was and where it was caused. Debug your server code and/or check event logs etc.
– ADyson
Nov 9 '18 at 12:30
1
P.S. you're not required to send your data as JSON - if you simply dodata: jsonObj(and remove thecontentTypeoption) then jQuery will encode it for you into standard querystring format and put it in the body...try it, if it's the data which is causing the crash, that might be worth trying.
– ADyson
Nov 9 '18 at 12:32
I've tried quite a number of different proposed solutions some dating back 6 years, i have edited the original Post to show this and the results achieved, but still not getting the data from a js array to MVC action via ajax.
– Neal Rogers
Nov 12 '18 at 10:44
so you still haven't gone and looked to see what is causing the 500, then? Also please show us a sample of what's actually in thejArrayvariable, since that's the nub of the issue.
– ADyson
Nov 12 '18 at 11:30
Thge 500 error.. well for most of the attempts at passing the data, it is no longer applicable. (happens if I don't use JSON.stringify) or the last of those attempts I listed. So, I doubt it's any server side code. I do breakpoint the entry to the called Action, before there is any code,..but the other methods do work, except I get all my records with null values in them. I'll add the data via an Edit as well, now.
– Neal Rogers
Nov 12 '18 at 12:06
|
show 7 more comments
I've tried solutions from similar questions, but I'm not having any success.
I'm passing a jQuery object of array rows to anMVC5 controller action.
If I specify the action parameter as string, then it gets to ation, but the param is null.
If I specify the param as a List and the jquery array structure matches the List structure, I get a server 500 error.
I've tried the datatype, the content type etc as per other posts on SO, but no success.
Can someone please help.
List structure is:
public class ActionPermission2
{
public int ID = 0;
public int FKMenuID = 0;
public string ActionName = "";
public string Allowed = "";
public int PermissionType = 0;
public int PermissionTypeID = 0;
}
Action Method's attempted (one as a List of the actionPermissions and another as a string array :
public ActionResult UpdateModel2(List<ActionPermission2> menuPermissionsModel)
{
return Json(true, JsonRequestBehavior.AllowGet);
}
public ActionResult UpdateModelSA(string menuPermissionsModel)
{
return Json(true, JsonRequestBehavior.AllowGet);
}
JS and jQuery:
$('input[type=checkbox]').each(function ()
{
var datarow = {
"ID": pId,
"FKMenuID": mId,
"ActionName": actionName,
"Allowed": checked,
"PermissionType": "",
"PermissionTypeID": ptId
};
jsonObj.push(datarow);
}
});
$.ajax({
type: "POST",
//url: "@Url.Action("Update")", //string menuPermissionsModel
url: "@Url.Action("UpdateModel2")", //List<ActionPermission2> menuPermissionsModel
//url: "@Url.Action("UpdateModelSA2")", //List<string> menuPermissionsModel
data: JSON.stringify({ 'menuPermissionsModel': jArray }),
traditional: true,
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (data)
{
alert('data: ' + data);
},
error: function (data)
{
alert("error");
console.log(data);
}
});
when directing the ajax call to the List param,..there are all the records, but they all show the default values as per the class in which it is constructed,..i.e. no data.
Edit2: Data ex console.log.
[{"ID":"0","FKMenuID":"38","ActionName":"Read","Allowed":false,"PermissionType":"","PermissionTypeID":"0"},
{"ID":"0","FKMenuID":"38","ActionName":"Create","Allowed":false,"PermissionType":"","PermissionTypeID":"0"},
{"ID":"0","FKMenuID":"38","ActionName":"Update","Allowed":false,"PermissionType":"","PermissionTypeID":"0"},
{"ID":"0","FKMenuID":"38","ActionName":"Delete","Allowed":false,"PermissionType":"","PermissionTypeID":"0"},
{"ID":"0","FKMenuID":"65","ActionName":"Read","Allowed":false,"PermissionType":"","PermissionTypeID":"0"},
{"ID":"0","FKMenuID":"65","ActionName":"Create","Allowed":false,"PermissionType":"","PermissionTypeID":"0"},
{"ID":"0","FKMenuID":"50","ActionName":"Delete","Allowed":false,"PermissionType":"","PermissionTypeID":"0"},
{"ID":"0","FKMenuID":"67","ActionName":"Read","Allowed":false,"PermissionType":"","PermissionTypeID":"0"},
{"ID":"0","FKMenuID":"67","ActionName":"Create","Allowed":false,"PermissionType":"","PermissionTypeID":"0"},
{"ID":"0","FKMenuID":"67","ActionName":"Update","Allowed":false,"PermissionType":"","PermissionTypeID":"0"},
{"ID":"0","FKMenuID":"67","ActionName":"Delete","Allowed":false,"PermissionType":"","PermissionTypeID":"0"}]
jquery arrays json ajax asp.net-mvc-5
I've tried solutions from similar questions, but I'm not having any success.
I'm passing a jQuery object of array rows to anMVC5 controller action.
If I specify the action parameter as string, then it gets to ation, but the param is null.
If I specify the param as a List and the jquery array structure matches the List structure, I get a server 500 error.
I've tried the datatype, the content type etc as per other posts on SO, but no success.
Can someone please help.
List structure is:
public class ActionPermission2
{
public int ID = 0;
public int FKMenuID = 0;
public string ActionName = "";
public string Allowed = "";
public int PermissionType = 0;
public int PermissionTypeID = 0;
}
Action Method's attempted (one as a List of the actionPermissions and another as a string array :
public ActionResult UpdateModel2(List<ActionPermission2> menuPermissionsModel)
{
return Json(true, JsonRequestBehavior.AllowGet);
}
public ActionResult UpdateModelSA(string menuPermissionsModel)
{
return Json(true, JsonRequestBehavior.AllowGet);
}
JS and jQuery:
$('input[type=checkbox]').each(function ()
{
var datarow = {
"ID": pId,
"FKMenuID": mId,
"ActionName": actionName,
"Allowed": checked,
"PermissionType": "",
"PermissionTypeID": ptId
};
jsonObj.push(datarow);
}
});
$.ajax({
type: "POST",
//url: "@Url.Action("Update")", //string menuPermissionsModel
url: "@Url.Action("UpdateModel2")", //List<ActionPermission2> menuPermissionsModel
//url: "@Url.Action("UpdateModelSA2")", //List<string> menuPermissionsModel
data: JSON.stringify({ 'menuPermissionsModel': jArray }),
traditional: true,
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (data)
{
alert('data: ' + data);
},
error: function (data)
{
alert("error");
console.log(data);
}
});
when directing the ajax call to the List param,..there are all the records, but they all show the default values as per the class in which it is constructed,..i.e. no data.
Edit2: Data ex console.log.
[{"ID":"0","FKMenuID":"38","ActionName":"Read","Allowed":false,"PermissionType":"","PermissionTypeID":"0"},
{"ID":"0","FKMenuID":"38","ActionName":"Create","Allowed":false,"PermissionType":"","PermissionTypeID":"0"},
{"ID":"0","FKMenuID":"38","ActionName":"Update","Allowed":false,"PermissionType":"","PermissionTypeID":"0"},
{"ID":"0","FKMenuID":"38","ActionName":"Delete","Allowed":false,"PermissionType":"","PermissionTypeID":"0"},
{"ID":"0","FKMenuID":"65","ActionName":"Read","Allowed":false,"PermissionType":"","PermissionTypeID":"0"},
{"ID":"0","FKMenuID":"65","ActionName":"Create","Allowed":false,"PermissionType":"","PermissionTypeID":"0"},
{"ID":"0","FKMenuID":"50","ActionName":"Delete","Allowed":false,"PermissionType":"","PermissionTypeID":"0"},
{"ID":"0","FKMenuID":"67","ActionName":"Read","Allowed":false,"PermissionType":"","PermissionTypeID":"0"},
{"ID":"0","FKMenuID":"67","ActionName":"Create","Allowed":false,"PermissionType":"","PermissionTypeID":"0"},
{"ID":"0","FKMenuID":"67","ActionName":"Update","Allowed":false,"PermissionType":"","PermissionTypeID":"0"},
{"ID":"0","FKMenuID":"67","ActionName":"Delete","Allowed":false,"PermissionType":"","PermissionTypeID":"0"}]
[{"ID":"0","FKMenuID":"38","ActionName":"Read","Allowed":false,"PermissionType":"","PermissionTypeID":"0"},
{"ID":"0","FKMenuID":"38","ActionName":"Create","Allowed":false,"PermissionType":"","PermissionTypeID":"0"},
{"ID":"0","FKMenuID":"38","ActionName":"Update","Allowed":false,"PermissionType":"","PermissionTypeID":"0"},
{"ID":"0","FKMenuID":"38","ActionName":"Delete","Allowed":false,"PermissionType":"","PermissionTypeID":"0"},
{"ID":"0","FKMenuID":"65","ActionName":"Read","Allowed":false,"PermissionType":"","PermissionTypeID":"0"},
{"ID":"0","FKMenuID":"65","ActionName":"Create","Allowed":false,"PermissionType":"","PermissionTypeID":"0"},
{"ID":"0","FKMenuID":"50","ActionName":"Delete","Allowed":false,"PermissionType":"","PermissionTypeID":"0"},
{"ID":"0","FKMenuID":"67","ActionName":"Read","Allowed":false,"PermissionType":"","PermissionTypeID":"0"},
{"ID":"0","FKMenuID":"67","ActionName":"Create","Allowed":false,"PermissionType":"","PermissionTypeID":"0"},
{"ID":"0","FKMenuID":"67","ActionName":"Update","Allowed":false,"PermissionType":"","PermissionTypeID":"0"},
{"ID":"0","FKMenuID":"67","ActionName":"Delete","Allowed":false,"PermissionType":"","PermissionTypeID":"0"}][{"ID":"0","FKMenuID":"38","ActionName":"Read","Allowed":false,"PermissionType":"","PermissionTypeID":"0"},
{"ID":"0","FKMenuID":"38","ActionName":"Create","Allowed":false,"PermissionType":"","PermissionTypeID":"0"},
{"ID":"0","FKMenuID":"38","ActionName":"Update","Allowed":false,"PermissionType":"","PermissionTypeID":"0"},
{"ID":"0","FKMenuID":"38","ActionName":"Delete","Allowed":false,"PermissionType":"","PermissionTypeID":"0"},
{"ID":"0","FKMenuID":"65","ActionName":"Read","Allowed":false,"PermissionType":"","PermissionTypeID":"0"},
{"ID":"0","FKMenuID":"65","ActionName":"Create","Allowed":false,"PermissionType":"","PermissionTypeID":"0"},
{"ID":"0","FKMenuID":"50","ActionName":"Delete","Allowed":false,"PermissionType":"","PermissionTypeID":"0"},
{"ID":"0","FKMenuID":"67","ActionName":"Read","Allowed":false,"PermissionType":"","PermissionTypeID":"0"},
{"ID":"0","FKMenuID":"67","ActionName":"Create","Allowed":false,"PermissionType":"","PermissionTypeID":"0"},
{"ID":"0","FKMenuID":"67","ActionName":"Update","Allowed":false,"PermissionType":"","PermissionTypeID":"0"},
{"ID":"0","FKMenuID":"67","ActionName":"Delete","Allowed":false,"PermissionType":"","PermissionTypeID":"0"}]jquery arrays json ajax asp.net-mvc-5
jquery arrays json ajax asp.net-mvc-5
edited Nov 13 '18 at 7:58
Neal Rogers
asked Nov 9 '18 at 12:22
Neal RogersNeal Rogers
54113
54113
1
"I get a server 500 error."....so, that means the server crashed with an exception. The first thing you need to do before asking a question is find out what the exception was and where it was caused. Debug your server code and/or check event logs etc.
– ADyson
Nov 9 '18 at 12:30
1
P.S. you're not required to send your data as JSON - if you simply dodata: jsonObj(and remove thecontentTypeoption) then jQuery will encode it for you into standard querystring format and put it in the body...try it, if it's the data which is causing the crash, that might be worth trying.
– ADyson
Nov 9 '18 at 12:32
I've tried quite a number of different proposed solutions some dating back 6 years, i have edited the original Post to show this and the results achieved, but still not getting the data from a js array to MVC action via ajax.
– Neal Rogers
Nov 12 '18 at 10:44
so you still haven't gone and looked to see what is causing the 500, then? Also please show us a sample of what's actually in thejArrayvariable, since that's the nub of the issue.
– ADyson
Nov 12 '18 at 11:30
Thge 500 error.. well for most of the attempts at passing the data, it is no longer applicable. (happens if I don't use JSON.stringify) or the last of those attempts I listed. So, I doubt it's any server side code. I do breakpoint the entry to the called Action, before there is any code,..but the other methods do work, except I get all my records with null values in them. I'll add the data via an Edit as well, now.
– Neal Rogers
Nov 12 '18 at 12:06
|
show 7 more comments
1
"I get a server 500 error."....so, that means the server crashed with an exception. The first thing you need to do before asking a question is find out what the exception was and where it was caused. Debug your server code and/or check event logs etc.
– ADyson
Nov 9 '18 at 12:30
1
P.S. you're not required to send your data as JSON - if you simply dodata: jsonObj(and remove thecontentTypeoption) then jQuery will encode it for you into standard querystring format and put it in the body...try it, if it's the data which is causing the crash, that might be worth trying.
– ADyson
Nov 9 '18 at 12:32
I've tried quite a number of different proposed solutions some dating back 6 years, i have edited the original Post to show this and the results achieved, but still not getting the data from a js array to MVC action via ajax.
– Neal Rogers
Nov 12 '18 at 10:44
so you still haven't gone and looked to see what is causing the 500, then? Also please show us a sample of what's actually in thejArrayvariable, since that's the nub of the issue.
– ADyson
Nov 12 '18 at 11:30
Thge 500 error.. well for most of the attempts at passing the data, it is no longer applicable. (happens if I don't use JSON.stringify) or the last of those attempts I listed. So, I doubt it's any server side code. I do breakpoint the entry to the called Action, before there is any code,..but the other methods do work, except I get all my records with null values in them. I'll add the data via an Edit as well, now.
– Neal Rogers
Nov 12 '18 at 12:06
1
1
"I get a server 500 error."....so, that means the server crashed with an exception. The first thing you need to do before asking a question is find out what the exception was and where it was caused. Debug your server code and/or check event logs etc.
– ADyson
Nov 9 '18 at 12:30
"I get a server 500 error."....so, that means the server crashed with an exception. The first thing you need to do before asking a question is find out what the exception was and where it was caused. Debug your server code and/or check event logs etc.
– ADyson
Nov 9 '18 at 12:30
1
1
P.S. you're not required to send your data as JSON - if you simply do
data: jsonObj (and remove the contentType option) then jQuery will encode it for you into standard querystring format and put it in the body...try it, if it's the data which is causing the crash, that might be worth trying.– ADyson
Nov 9 '18 at 12:32
P.S. you're not required to send your data as JSON - if you simply do
data: jsonObj (and remove the contentType option) then jQuery will encode it for you into standard querystring format and put it in the body...try it, if it's the data which is causing the crash, that might be worth trying.– ADyson
Nov 9 '18 at 12:32
I've tried quite a number of different proposed solutions some dating back 6 years, i have edited the original Post to show this and the results achieved, but still not getting the data from a js array to MVC action via ajax.
– Neal Rogers
Nov 12 '18 at 10:44
I've tried quite a number of different proposed solutions some dating back 6 years, i have edited the original Post to show this and the results achieved, but still not getting the data from a js array to MVC action via ajax.
– Neal Rogers
Nov 12 '18 at 10:44
so you still haven't gone and looked to see what is causing the 500, then? Also please show us a sample of what's actually in the
jArray variable, since that's the nub of the issue.– ADyson
Nov 12 '18 at 11:30
so you still haven't gone and looked to see what is causing the 500, then? Also please show us a sample of what's actually in the
jArray variable, since that's the nub of the issue.– ADyson
Nov 12 '18 at 11:30
Thge 500 error.. well for most of the attempts at passing the data, it is no longer applicable. (happens if I don't use JSON.stringify) or the last of those attempts I listed. So, I doubt it's any server side code. I do breakpoint the entry to the called Action, before there is any code,..but the other methods do work, except I get all my records with null values in them. I'll add the data via an Edit as well, now.
– Neal Rogers
Nov 12 '18 at 12:06
Thge 500 error.. well for most of the attempts at passing the data, it is no longer applicable. (happens if I don't use JSON.stringify) or the last of those attempts I listed. So, I doubt it's any server side code. I do breakpoint the entry to the called Action, before there is any code,..but the other methods do work, except I get all my records with null values in them. I'll add the data via an Edit as well, now.
– Neal Rogers
Nov 12 '18 at 12:06
|
show 7 more comments
1 Answer
1
active
oldest
votes
The answer to my question is;
I changed my base class from what was posted to the following;
public class ActionPermission2
{
public int ID { get; set; }
public int FKMenuID { get; set; }
public string ActionName { get; set; }
public string Allowed { get; set; }
public string PermissionType { get; set; }
public int PermissionTypeID { get; set; }
public ActionPermission2()
{
this.ID = 0;
this.FKMenuID = 0;
this.ActionName = "";
this.Allowed = "false";
this.PermissionType = "";
this.PermissionTypeID = 0;
}
}
Now I get the records as before in the parameter of the action method, ..only now they show the values populated in the js array of objects.
I also changed the datatype of "Allowed" from bool to string, as that caused a 500 error response.
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%2f53225650%2fpass-array-of-json-objects-to-mvc-5-action-via-jquery-ajax-and-the-action-param%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
The answer to my question is;
I changed my base class from what was posted to the following;
public class ActionPermission2
{
public int ID { get; set; }
public int FKMenuID { get; set; }
public string ActionName { get; set; }
public string Allowed { get; set; }
public string PermissionType { get; set; }
public int PermissionTypeID { get; set; }
public ActionPermission2()
{
this.ID = 0;
this.FKMenuID = 0;
this.ActionName = "";
this.Allowed = "false";
this.PermissionType = "";
this.PermissionTypeID = 0;
}
}
Now I get the records as before in the parameter of the action method, ..only now they show the values populated in the js array of objects.
I also changed the datatype of "Allowed" from bool to string, as that caused a 500 error response.
add a comment |
The answer to my question is;
I changed my base class from what was posted to the following;
public class ActionPermission2
{
public int ID { get; set; }
public int FKMenuID { get; set; }
public string ActionName { get; set; }
public string Allowed { get; set; }
public string PermissionType { get; set; }
public int PermissionTypeID { get; set; }
public ActionPermission2()
{
this.ID = 0;
this.FKMenuID = 0;
this.ActionName = "";
this.Allowed = "false";
this.PermissionType = "";
this.PermissionTypeID = 0;
}
}
Now I get the records as before in the parameter of the action method, ..only now they show the values populated in the js array of objects.
I also changed the datatype of "Allowed" from bool to string, as that caused a 500 error response.
add a comment |
The answer to my question is;
I changed my base class from what was posted to the following;
public class ActionPermission2
{
public int ID { get; set; }
public int FKMenuID { get; set; }
public string ActionName { get; set; }
public string Allowed { get; set; }
public string PermissionType { get; set; }
public int PermissionTypeID { get; set; }
public ActionPermission2()
{
this.ID = 0;
this.FKMenuID = 0;
this.ActionName = "";
this.Allowed = "false";
this.PermissionType = "";
this.PermissionTypeID = 0;
}
}
Now I get the records as before in the parameter of the action method, ..only now they show the values populated in the js array of objects.
I also changed the datatype of "Allowed" from bool to string, as that caused a 500 error response.
The answer to my question is;
I changed my base class from what was posted to the following;
public class ActionPermission2
{
public int ID { get; set; }
public int FKMenuID { get; set; }
public string ActionName { get; set; }
public string Allowed { get; set; }
public string PermissionType { get; set; }
public int PermissionTypeID { get; set; }
public ActionPermission2()
{
this.ID = 0;
this.FKMenuID = 0;
this.ActionName = "";
this.Allowed = "false";
this.PermissionType = "";
this.PermissionTypeID = 0;
}
}
Now I get the records as before in the parameter of the action method, ..only now they show the values populated in the js array of objects.
I also changed the datatype of "Allowed" from bool to string, as that caused a 500 error response.
answered Nov 13 '18 at 8:43
Neal RogersNeal Rogers
54113
54113
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%2f53225650%2fpass-array-of-json-objects-to-mvc-5-action-via-jquery-ajax-and-the-action-param%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
1
"I get a server 500 error."....so, that means the server crashed with an exception. The first thing you need to do before asking a question is find out what the exception was and where it was caused. Debug your server code and/or check event logs etc.
– ADyson
Nov 9 '18 at 12:30
1
P.S. you're not required to send your data as JSON - if you simply do
data: jsonObj(and remove thecontentTypeoption) then jQuery will encode it for you into standard querystring format and put it in the body...try it, if it's the data which is causing the crash, that might be worth trying.– ADyson
Nov 9 '18 at 12:32
I've tried quite a number of different proposed solutions some dating back 6 years, i have edited the original Post to show this and the results achieved, but still not getting the data from a js array to MVC action via ajax.
– Neal Rogers
Nov 12 '18 at 10:44
so you still haven't gone and looked to see what is causing the 500, then? Also please show us a sample of what's actually in the
jArrayvariable, since that's the nub of the issue.– ADyson
Nov 12 '18 at 11:30
Thge 500 error.. well for most of the attempts at passing the data, it is no longer applicable. (happens if I don't use JSON.stringify) or the last of those attempts I listed. So, I doubt it's any server side code. I do breakpoint the entry to the called Action, before there is any code,..but the other methods do work, except I get all my records with null values in them. I'll add the data via an Edit as well, now.
– Neal Rogers
Nov 12 '18 at 12:06