xort xort - 6 months ago 82
Javascript Question

The parameters dictionary contains a null entry for parameter 'imageWidth' of non-nullable type 'System.Int32'

I have a function that makes an ajax call to an ActionResult, it sends a base64 string of an uploaded image along with some other params with information about the dimensions of the image. The data is sent to the server for resizing among other stuff. The ajax call looks like this

type: 'POST',
data: {
b64: data.data,
imageWidth: data.imageWidth,
imageHeight: data.imageHeight,
imageOriginalWidth: data.imageOriginalWidth,
imageOriginalHeight: data.imageOriginalHeight

url: '/Image/Resize',
beforeSend: function () {
success: function (data) {
error: function (response) {

The data object is retrieved from a callback function that gets all the information I mentioned above. Now, I put breakpoints and made sure that the object actually has values.

I also looked at the request in Fiddler and everything looks fine. The weird thing is that this doesn't always happen. It happens only when I try to upload a gif that is too large. The error doesn't happen when a file isn't bigger than about 2MB. To clarify, I'm not sending the file, just the base64 string.

I don't know if the problem is that the
string is too large or something else, but looking at the response from the server all I see is this

The parameters dictionary contains a null entry for parameter 'imageWidth' of non-nullable type 'System.Int32' for method 'System.Web.Mvc.ActionResult Resize(System.String, Int32, Int32, Int32, Int32)'

Here is what the ActionResult looks like

public ActionResult Resize(String b64, int imageWidth, int imageHeight, int imageOriginalWidth, int imageOriginalHeight)


When I try and upload another file that is smaller, everything works fine and it doesn't give me this error. I'm sorry if this question has been answered before but I've looked everywhere and haven't found an answer. I've tried changing the
in the ajax call, I've tried stringifying and looked at the request headers.

Content-Length: 4849982
Content-Type: application/x-www-form-urlencoded; charset=UTF-8

I don't know what I'm missing. Any help would be appreciated. Thanks, guys.


b64 edited out

imageWidth 906

imageHeight 509

imageOriginalWidth 500

imageOriginalHeight 281


Finally found a solution to this. It turns out that the default limit for the input stream buffering threshold when a request is made to the server is 4 MB

All you need to do is to go to your web.config file and add the following:

    <httpRuntime maxRequestLength="xxx" />

where "xxx" is the size you want in KB

For IIS 7+ you also need to add the following:

      <requestLimits maxAllowedContentLength="xxx" />

The default value is equivalent to 30 MB