Hi,
I have a simple controller that receives as a parameter an IList<MyObject> where MyObject has 2 integer fields, defined as:
public class MyObject
{
public int First { get; set; }
public int Second { get; set; }
} In the view, I have 4 fields, to enter information about 2 MyObjects object. When I submit the form with non numeric data, the validation triggers as expected, and the controller redirects the user to the same view, which renders the fields with the red border. However, if I press the submit button once again in there, I get a NullReferenceException. What am I doing wrong? The exception is triggered even before the controller starts.
Here's the stack trace:
[NullReferenceException: Object reference not set to an instance of an object.]
System.Web.Mvc.DefaultModelBinder.UpdateCollection(ModelBindingContext bindingContext, Type itemType) +613
System.Web.Mvc.DefaultModelBinder.BindModelCore(ModelBindingContext bindingContext) +519
System.Web.Mvc.DefaultModelBinder.BindModel(ModelBindingContext bindingContext) +829
System.Web.Mvc.ControllerActionInvoker.GetParameterValue(ParameterInfo parameterInfo) +313
System.Web.Mvc.ControllerActionInvoker.GetParameterValues(MethodInfo methodInfo) +399
System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName) +232
System.Web.Mvc.Controller.ExecuteCore() +152
System.Web.Mvc.ControllerBase.Execute(RequestContext requestContext) +86
System.Web.Mvc.ControllerBase.System.Web.Mvc.IController.Execute(RequestContext requestContext) +28
System.Web.Mvc.MvcHandler.ProcessRequest(HttpContextBase httpContext) +332
System.Web.Mvc.MvcHandler.ProcessRequest(HttpContext httpContext) +55
System.Web.Mvc.MvcHandler.System.Web.IHttpHandler.ProcessRequest(HttpContext httpContext) +28
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +358
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +64
Any idea? Thank you in advance.