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

4

3 回答 3

0

你只需@Html.DisplayFor(m => m.RequestOnSiteDate)要从你的代码中删除,你就永远不会看到这个名字。

于 2011-07-29T16:02:21.280 回答
0

估计...

不是在模型的 DisplayName 属性上使用 [Required] ,而是在 setter 内部有一个陷阱,它会在 null 值上引发异常,并且活页夹正在尝试将属性设置为 null,因为这是来自表单的内容。

给我们模型代码(可能还有控制器操作方法),这样我们就能得到更好的主意。

于 2011-07-29T10:22:18.500 回答
0

安德斯,几年后,我在 MVC4 中遇到了完全相同的错误。

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

你有没有解决它?我通过以下方式解决了它:

[DisplayName(" ")]
public NexEnum.Veteran Veteran { get; set; }
于 2015-06-29T18:45:40.180 回答