First, let me start by saying that, though I'm a seasoned developer with 30 years behind the keyboard, I've only been working with web development for about a year, so there are things I don't know. However, this one really has me confused!
All I want to do is send an array of integers to an MVC controller using an AJAX call. The code below works absolutely perfectly for me every single time I run it in my development environment (Windows 10, VS2017), BUT, when I roll it out to the production server (running IIS 7.5), I get an error 500, internal server error. To make matters worse, this code WORKED on the production environment 1 week ago, and yesterday it decided "screw you!" and started to fail.
Note, when it errors, it jumps into the error part of the Ajax call; it never gets into the controller method, I guess because it doesn't like the int[] parameter anymore...
Here is my AJAX call:
var selectedItems =newArray();
$("input:checkbox[name=selectPrice]:checked").each(function(){
selectedItems.push(this.id);});if(selectedItems.length >0){
$.ajax({
url:"/ProductPrice/CanApprove",
type:"post",
dataType:"json",
contextType:"application/json",
data:{ selectedIds: selectedItems },
traditional:true,
success:function(result){if(result.success){//Do something useful}else{//It all went wrong}},
error:function(_err){//It all went REALLY wrong}});}
And here is my controller method:
[Authorize][HttpPost]publicJsonResultCanApprove(int[] selectedIds){bool canApprove = service.CanApprove(selectedIds, out string reason, out int[] approvableIDs);returnJson(new{ success = canApprove, ex = reason, approvableIDList = approvableIDs },JsonRequestBehavior.AllowGet);}
I've had to change over to just passing a delimited string for now, and converting it back into an array inside my controller method (which is just urgh!), but I'm REALLY struggling to understand why this just stopped working?! Is there anyone here with more javascript experience than me that can explain what could have caused this?
Question
FloatingFatMan
First, let me start by saying that, though I'm a seasoned developer with 30 years behind the keyboard, I've only been working with web development for about a year, so there are things I don't know. However, this one really has me confused!
All I want to do is send an array of integers to an MVC controller using an AJAX call. The code below works absolutely perfectly for me every single time I run it in my development environment (Windows 10, VS2017), BUT, when I roll it out to the production server (running IIS 7.5), I get an error 500, internal server error. To make matters worse, this code WORKED on the production environment 1 week ago, and yesterday it decided "screw you!" and started to fail.
Note, when it errors, it jumps into the error part of the Ajax call; it never gets into the controller method, I guess because it doesn't like the int[] parameter anymore...
Here is my AJAX call:
And here is my controller method:
I've had to change over to just passing a delimited string for now, and converting it back into an array inside my controller method (which is just urgh!), but I'm REALLY struggling to understand why this just stopped working?! Is there anyone here with more javascript experience than me that can explain what could have caused this?
Link to comment
Share on other sites
6 answers to this question
Recommended Posts