Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/asp.net-mvc-3/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net mvc 3 MVC3值不能为空。参数名称:value_Asp.net Mvc 3_Entity Framework - Fatal编程技术网

Asp.net mvc 3 MVC3值不能为空。参数名称:value

Asp.net mvc 3 MVC3值不能为空。参数名称:value,asp.net-mvc-3,entity-framework,Asp.net Mvc 3,Entity Framework,我试图加载一个用户的数据,编辑它,然后保存它。这一直在工作,我不太确定我改变了什么,但现在我得到以下错误 Value cannot be null. Parameter name: value Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about t

我试图加载一个用户的数据,编辑它,然后保存它。这一直在工作,我不太确定我改变了什么,但现在我得到以下错误

Value cannot be null.
Parameter name: value

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.ArgumentNullException: Value cannot be null.
Parameter name: value

Source Error: 

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

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() +8897857
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +184


     public ActionResult EditDetails()
    {
        int id = Convert.ToInt32(Session["user"]);
        S1_Customers u1_users = storeDB.S1_Customers.Find(id);
        return View(u1_users);
    }

    [HttpPost]
    public ActionResult EditDetails(S1_Customers u1_users)
    {
        var Pcode = "";  
        if (ModelState.IsValid)
        {
值不能为空。
参数名称:value
描述:执行当前web请求期间发生未处理的异常。请查看堆栈跟踪以了解有关错误的更多信息以及错误在代码中的起源。
异常详细信息:System.ArgumentNullException:值不能为null。
参数名称:value
源错误:
在执行当前web请求期间生成了未经处理的异常。有关异常的起源和位置的信息可以使用下面的异常堆栈跟踪来识别。
堆栈跟踪:
[ArgumentNullException:值不能为null。
参数名称:值]
System.ComponentModel.DataAnnotations.ValidationContext.set_DisplayName(字符串值)+51903
System.Web.Mvc.d__1.MoveNext()+135
System.Web.Mvc.d__5.MoveNext()+318
System.Web.Mvc.DefaultModelBinder.OnModelUpdated(ControllerContext ControllerContext,ModelBindingContext bindingContext)+139
System.Web.Mvc.DefaultModelBinder.BindCompleteXelementalModel(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__显示类b.b__5()+37
System.Web.Mvc.Async.c__显示类1.b__0()+21
System.Web.Mvc.Async.c_uuudisplayClass8`1.b_uuu7(IAsyncResult)+12
System.Web.Mvc.Async.WrappedAsyncResult`1.End()+62
System.Web.Mvc.c_uuudisplayClasse.b_uuud()+50
System.Web.Mvc.SecurityUtil.b___0(操作f)+7
System.Web.Mvc.SecurityUtil.ProcessInApplicationTrust(操作)+22
System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult)+60
System.Web.Mvc.MvcHandler.System.Web.IHTTPassynchandler.EndProcessRequest(IAsyncResult结果)+9
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()+8897857
System.Web.HttpApplication.ExecuteStep(IExecutionStep步骤,布尔值&同步完成)+184
公共行动结果编辑详细信息()
{
int id=Convert.ToInt32(会话[“用户]);
S1_Customers u1_users=storeDB.S1_Customers.Find(id);
返回视图(u1_用户);
}
[HttpPost]
公共行动结果编辑详细信息(S1_客户u1_用户)
{
var Pcode=“”;
if(ModelState.IsValid)
{

我甚至没有到达ModelState。单击“提交”时是否有效?是否更改了任何名称?表单名称必须与您的操作参数映射1-1。在这种情况下,“名称”参数未传递给控制器操作,因此为空


胡乱猜测,需要更多信息(操作的方法签名)很可能是您的模型有一个返回不可为空值的属性,如
int
DateTime
double
等。如果用户正在更新条目,您可能没有将该值存储在隐藏字段或某处,因此当返回数据时,该特定属性为空将该属性转换为隐藏字段,或通过将int更改为int?等方式使您的属性在模型中为空。

如果您的某些属性由DisplayAttribute修饰为空名称,则会收到该错误
([DisplayAttribute(Name=”,Description=“Any Description”)])

如果对模型的属性使用[Display(Name=”)],这将导致出现错误。要解决此问题,应避免使用空的显示名称属性

[Display(Name = "")] //this line is the cause of error
public string PromotionCode { get; set; }

手动设置
@Html.TextArea
时,我收到了相同的错误消息,我在EditorTemplate中使用了
@Html.TextBox(null,this.Model)
中的代码,当我执行
@Html.TextArea(null,this.Model)
时,我得到了上面的错误


事实证明,您必须执行
@Html.TextArea(“,this.Model)”
,并且它可以正常工作。

请发布您的模型代码,以及您为保存此模型而调用的操作。验证似乎存在一些问题,但需要更多信息……为什么这个问题会被否决?啊,我真傻,这是因为我这样做了…[显示(名称=”)]公共字符串地址{get;set;}我不确定这是否是同一个问题,但如果我应用一个具有StringLength属性的成员并同时应用[DisplayName(“”),我会得到相同的异常。是的,StringLength和DisplayName(“”)也给我造成了同样的问题。我做了同样的事情,作为一个厚颜无耻的黑客来更改jquery验证的文本,我想我现在必须正确地修复它!从验证中删除字段名的另一个厚颜无耻的黑客是
[Display(name=”“)]请注意空格字符。我不敢相信我花了这么长时间才回答这个问题。