I have a request to one of my actions in a controller that expects an enum as a key in the Querystring. I can see that the same is set in the QueryString but an exception is thrown by the server saying the same is not set and the error:
The parameters dictionary contains a null entry for parameter ‘enumVar’ of non-nullable type.
is thrown.
Here are the exception details:
Exception type: System.ArgumentException
Exception message: The parameters dictionary contains a null entry for parameter ‘enumVar’ of non-nullable type ‘NameSpace.Enums.MyEnum’ for method ‘System.Web.Mvc.ActionResult GetContent(Int64, NameSpace.Enums.MyEnum, System.String, Int32, Int32, Int32, Int32, Int64)’ in ‘NameSpace.Controllers.MyController’. An optional parameter must be a reference type, a nullable type, or be declared as an optional parameter.
Parameter name: parameters
Request path: app/My/GetContent
Let me know if you need more information. I am not sure how I should address the issue.
Update:
My Enum defination:
public enum DisplayMode
{
EnumValue,
EnumValue1,
EnumValue2
}
Also I should mention that the request fails only sometimes and not always and this is not consistent. This is an error that was logged in our exception db.
It looks like the Default Model Binder is not dailed into enumerations. Your best bet would be to subclass the
DefaultModelBinderclass and handle the scenario where a property is an enum.Code and logic courtesy of this question.