I have a simple jQuery ajax method:
var sendData = { personId: "@(Guid.Empty)"};
$.ajax({
type: "POST",
url: "@(Url.Action("Dialog", "Dialog")",
data: sendData;
}).done(function (e) {
$('#dialog').html(e);
window.resizeDialog();
});
In the dialogController:
public ActionResult PersonInfo(Guid personId)
{
....
}
jQuery will pass a personId as Guid to the controller and the controller will do it’s stuff and return a PartialView as dialog.
This works fine and is being used quite alot in a few big project with numerous users.
But rarely (around 1 per 10.000 hits) I get this exception by our logger:
22-8-2012 14:17:27 ERROR: The parameters dictionary contains a null entry for parameter 'personId' of non-nullable type 'System.Guid' for method 'System.Web.Mvc.ActionResult PersonInfo(System.Guid)' in 'Site.Controllers.DialogController'. An optional parameter must be a reference type, a nullable type, or be declared as an optional parameter.
Parameter name: parameters at System.Web.Mvc.ActionDescriptor.ExtractParameterFromDictionary(ParameterInfo parameterInfo, IDictionary`2 parameters, MethodInfo methodInfo)
at System.Web.Mvc.ReflectedActionDescriptor.<>c__DisplayClass1.b__0(ParameterInfo parameterInfo)
at System.Linq.Enumerable.WhereSelectArrayIterator`2.MoveNext()
at System.Linq.Buffer`1..ctor(IEnumerable`1 source)
at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source)
at System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters)
at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters)
at System.Web.Mvc.ControllerActionInvoker.<>c__DisplayClass15.b__12()
at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation)
at System.Web.Mvc.ControllerActionInvoker.<>c__DisplayClass15.<>c__DisplayClass17.b__14()
at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation)
at System.Web.Mvc.ControllerActionInvoker.<>c__DisplayClass15.<>c__DisplayClass17.b__14()
at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodWithFilters(ControllerContext controllerContext, IList`1 filters, ActionDescriptor actionDescriptor, IDictionary`2 parameters)
at System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName)
What I tried was changing the DataType of the $.ajax method, but it didn’t help. Now I found out that MOST (not all) errors come from IE8 (90%).
What could be wrong here and how can I prevent this? For some methods I made all arguments nullable and I will check for null later in the method, but this is not optimal because the request will fail.
I would say this is more likely a problem with the data your sending up. I noticed you are posting the JSON object “raw” (without any type of parsing) which could be where the problem is. Try using JSON.parse or a 3rd party library like JSON2.js (cross browser) and see if your problem goes away.