4

After upgrade I get this error for some of the views.

Value cannot be null. Parameter name: value

Stack trace

[ArgumentNullException: Value cannot be null.
Parameter name: value]
   System.ComponentModel.DataAnnotations.ValidationContext.set_DisplayName(String value) +51903
   System.Web.Mvc.<Validate>d__1.MoveNext() +135
   System.Web.Mvc.<Validate>d__5.MoveNext() +318
   System.Web.Mvc.DefaultModelBinder.OnModelUpdated(ControllerContext controllerContext, ModelBindingContext bindingContext) +139
   System.Web.Mvc.DefaultModelBinder.BindComplexElementalModel(ControllerContext controllerContext, ModelBindingContext bindingContext, Object model) +66
   System.Web.Mvc.DefaultModelBinder.BindComplexModel(ControllerContext controllerContext, ModelBindingContext bindingContext) +1367
   System.Web.Mvc.DefaultModelBinder.BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext) +449
   System.Web.Mvc.ControllerActionInvoker.GetParameterValue(ControllerContext controllerContext, ParameterDescriptor parameterDescriptor) +317
   System.Web.Mvc.ControllerActionInvoker.GetParameterValues(ControllerContext controllerContext, ActionDescriptor actionDescriptor) +117
   System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName) +343
   System.Web.Mvc.Controller.ExecuteCore() +116
   System.Web.Mvc.ControllerBase.Execute(RequestContext requestContext) +97
   System.Web.Mvc.ControllerBase.System.Web.Mvc.IController.Execute(RequestContext requestContext) +10
   System.Web.Mvc.<>c__DisplayClassb.<BeginProcessRequest>b__5() +37
   System.Web.Mvc.Async.<>c__DisplayClass1.<MakeVoidDelegate>b__0() +21
   System.Web.Mvc.Async.<>c__DisplayClass8`1.<BeginSynchronous>b__7(IAsyncResult _) +12
   System.Web.Mvc.Async.WrappedAsyncResult`1.End() +62
   System.Web.Mvc.<>c__DisplayClasse.<EndProcessRequest>b__d() +50
   System.Web.Mvc.SecurityUtil.<GetCallInAppTrustThunk>b__0(Action f) +7
   System.Web.Mvc.SecurityUtil.ProcessInApplicationTrust(Action action) +22
   System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +60
   System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +9
   System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +8920029
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +184

Any one have any idea that the problem can be?

edit: Found the problem,

[RequiredRequestedOnSiteDate]
[DisplayName("")]
public Date RequestedOnSiteDate { get; set; }

In MVC2 this works, we dont want a displayname for this textbox since the name is presented in a header. How can I have no displayname without error? Thanks

Anders
  • 17,306
  • 10
  • 76
  • 144
  • I'm having a similar issue but don't have the [DisplayName("")] attribute in my code. Did you happen to find any other cause of this issue while investigating by chance? – JamesEggers Feb 07 '12 at 16:16
  • Nope, that solved it, sorry that I cant help you... Also, that is a Linq exception, so probably you have a Linq query somewhere that is operating on a null collection (If you get the same exeption that I did in the above question) – Anders Feb 08 '12 at 08:05

3 Answers3

0

Anders, Here it is a couple years later and I'm having the exact same error in MVC4.

[DisplayName("")]
public NexEnum.Veteran Veteran { get; set; }

Did you ever resolve it? I resolved it by this:

[DisplayName(" ")]
public NexEnum.Veteran Veteran { get; set; }
A MIERS
  • 132
  • 10
0

At a guess...

Rather than using [Required] on the DisplayName attribute of your model, there's a trap inside the setter that's throwing an exception on a null value and the binder is attempting to set the property to null because that's what's coming in from the form.

Give us the Model code (and maybe controller action method) so that we can get a better idea.

Steve Morgan
  • 12,978
  • 2
  • 40
  • 49
0

You just have to remove the @Html.DisplayFor(m => m.RequestOnSiteDate) from your code and you'll never see the name.

Buildstarted
  • 26,529
  • 10
  • 84
  • 95
  • I'm not sure what you mean. You've already removed the name from `DisplayName` attribute so you seem to not want to see the name when using `DisplayFor` so removing the `DisplayFor` will still achieve what you want. It would be helpful to see your actual use-case so we can help you better. – Buildstarted Aug 01 '11 at 13:57