ccravenbartle
asked on
maxJsonLength exceeded error on ajax Post to ASP.NET MVC Controller Action method
I am getting the following error when my javascript attempts to execute the SaveUserCostCentreList MVC Controller Action using $.ajax Post. The error gets displayed before I can step into the method on the Server Controller.
Error during serialization or deserialization using the JSON JavaScriptSerializer. The length of the string exceeds the value set on the maxJsonLength property.
Parameter name: input
I have tried setting the maxJsonLength property and other properties relating to data sizes within the web.config but nothing works.
Server side, client side and web config snippets are listed below.
SERVER SIDE
CLIENT SIDE
WEB.CONFIG entries
Error during serialization or deserialization using the JSON JavaScriptSerializer. The length of the string exceeds the value set on the maxJsonLength property.
Parameter name: input
I have tried setting the maxJsonLength property and other properties relating to data sizes within the web.config but nothing works.
Server side, client side and web config snippets are listed below.
SERVER SIDE
[HttpPost]
public ActionResult SaveUserCostCentreList(UserVM userVm)
{
// error message is displayed without this ever getting executed
// do stuff with userVm
}
CLIENT SIDE
$.ajax({
url: '@Url.Action("SaveUserCostCentreList", "Admin")',
data: jsonString,
type: 'POST',
contentType: 'application/json',
dataType: 'json',
success: function (result) {
alert('ok');
}
});
WEB.CONFIG entries
<system.web>
<httpHandlers />
<authentication mode="None" />
<compilation debug="true" targetFramework="4.5">
<assemblies>
<add assembly="Microsoft.Build.Framework, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A" />
<add assembly="System.Management, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A" />
</assemblies>
<buildProviders />
</compilation>
<httpRuntime maxRequestLength="2000000000" />
</system.web>
<system.web.extensions>
<scripting>
<webServices>
<jsonSerialization maxJsonLength="2147483647">
</jsonSerialization>
</webServices>
</scripting>
</system.web.extensions>
<system.webServer>
<httpProtocol />
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="10485760" />
</requestFiltering>
</security>
</system.webServer>
ASKER
Hi Julian - thank you for your quick response.
Please clarify. Is this code which I have to add to the server Controller SaveUserCostCentreList method? I am uploading my json object view model to the controller using POST, Is this not applicable to server Get requests rather than server Post requests?
JavaScriptSerializer jss = new JavaScriptSerializer();
jss.MaxJsonLength = int.MaxValue;
...
return jss.Serialize(yourDataObje ct);.
Charles
Please clarify. Is this code which I have to add to the server Controller SaveUserCostCentreList method? I am uploading my json object view model to the controller using POST, Is this not applicable to server Get requests rather than server Post requests?
JavaScriptSerializer jss = new JavaScriptSerializer();
jss.MaxJsonLength = int.MaxValue;
...
return jss.Serialize(yourDataObje
Charles
Are you getting the error on the upload - I thought it was the download - did not read the question properly.
What does your .Net service code look like?
What does your .Net service code look like?
ASKER
Yes, it is on the upload. The method call works fine if I chop the data in half so I know there is nothing wrong with the Controller Action method itself.
[HttpPost]
public ActionResult SaveUserCostCentreList(Use rVM userVm)
{
// error message is displayed without this ever getting executed
// do stuff with userVm
}
[HttpPost]
public ActionResult SaveUserCostCentreList(Use
{
// error message is displayed without this ever getting executed
// do stuff with userVm
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Open in new window