2011-09-21 21 views
28

Bir kullanıcının verilerini yüklemeye çalışıyorum ve sonra onu kaydedin. Bu görev yapmaktadır ve im oldukça emin değil ben ne değiştirdi ama şimdi aşağıdaki hatayı alıyorum ... Ben bile ModelState.IsValid ulaşan değilimMVC3 Değer boş olamaz. Parametre adı: value

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) 
     { 

i

+2

Lütfen model kodunuzu ve bunu kaydetmek için aradığınız eylemi kaydedin .. Doğrulama ile ilgili bazı sorunlar var gibi görünüyor, ancak daha fazla bilgiye ihtiyaç var .... Bu soru neden aşağı indi? oy? –

cevap

24

herhangi değiştirdi mi göndermek tıkladığınızda isimler? Form isimleri, Eylem parametrelerinizle 1-1 eşleştirmelidir. Bu durumda, "isim" parametresi denetleyici eylemine geçirilmemiş, bu nedenle boştur.

Yabani tahminim, En muhtemelen modeli olmayan bir null değer döndüren bir özelliğe sahip olduğunu olabilir fazla bilgi (eylem yöntemi imzası)

+10

Ahh yeh aptal çünkü benim bunu yaptım çünkü ... [Ekran (Name = "")] public string Addrs {get; set; } – Beginner

+0

:) İyi olduğundan emin olun. –

+5

Aynı sorun olup olmadığından emin değilim ancak bir StringLength özniteliği olan bir üye uygular ve aynı zamanda [DisplayName ("")] uygularsanız aynı özel durumu alıyorum. –

2

ihtiyaç int, DateTime, double vb Ve kullanıcı eğer girişi güncelleştirdiğinizde muhtemelen bu değeri gizli bir alanda veya bir yerde saklamıyorsunuz, bu nedenle veriler döndüğünde belirli bir özellik boştur. Boş Adı DisplayAttribute tarafından dekore bazı özellikleri varsa vs. mülkiyet gizli alana veya int int değiştirerek bir model içinde mülkiyet Nullable yapmak ?,

16

O hatayı alacağınızı Ya yer ([DisplayAttribute(Name = "", Description = "Any description")])

+0

Bu cevaba gelmeden çok zaman geçirdiğime inanamıyorum. –

10

Modelinizin özellikleri için [Ekran (Ad = "")] özelliğini kullanırsanız, bu hataya neden olur. Bu sorunu çözmek için boş görünen ad özelliğini kullanmamanız gerekir.

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