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?
Trump is what a poor man thinks of as rich. (though I guess now with all the bribes and grifting he's got to be a real billionaire now, sigh)
Much like Elon is a dumb man's example of smart.
Windows 11 DHCP????? Maybe Windows Server 2025 DHCP. It is the same as 2022, 2019, and 2016. 2012 R2 brought big IPAM changes over previous versions.
That said we use Infoblox IPAM. Microsofts IPAM works pretty good, not counting this update.
Question
+FloatingFatMan Subscriber¹
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
https://www.neowin.net/forum/topic/1342926-sending-an-array-via-ajax-to-mvc-controller/Share on other sites
6 answers to this question
Recommended Posts