Warm tip: This article is reproduced from stackoverflow.com, please click
ajax asp.net-mvc jquery

Jquery Ajax "The parameters dictionary contains a null entry for parameter" error

发布于 2020-04-07 10:07:49

I've run into a problem with my AJAX call.

$.ajax({
  url: "/Admin/changeStudentPhoto/",
  type: "POST",
  data: {
    file: file1,
    filename: filename1,
    studentID: studentID1,
    x: x1,
    y: y1,
    w: w1,
    h: h1
  },
  success: function(data) {
    //do Stuff
  },
  error: function() {}
});

It sends the request to this controller:

public JsonResult changeStudentPhoto(string file, string filename, int studentID, double x, double y, double w, double h) { 
  // More Stuff 
}

The thing is that by applying a breakpoint on the call I can see that the parameters are properly set, I get an error 500 from the controller that includes an error:

The parameters dictionary contains a null entry for parameter 'h' of non-nullable type 'System.Double' for method

The specific parameter does not really matter, before h it was the studentID.

I usually place data directly in the URL but this time I need to also pass a base64 string so I can't place it in a URL.

Thanks in advance.

EDIT: Added pics for clarification

debugger

error

Questioner
MrNutbutters
Viewed
139
MrNutbutters 2020-01-31 19:12

I initialy turned my data to a Json and created a model for it to bind. That didn't really work though, the value for "h" would be shown as zero.

So i ended up rounding my numbers in js and passing them as ints. That solved the problem.

That is not a proper solution though since although in my case i can work with integers someone else might need to pass actual float numbers.