2011-09-21 36 views
28

Tôi đang cố gắng tải dữ liệu của người dùng chỉnh sửa và sau đó lưu nó. điều này đã được làm việc và im không khá chắc chắn những gì tôi đã thay đổi nhưng bây giờ tôi đang nhận được lỗi sau ...MVC3 không được rỗng. Tên thông số: giá trị

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

Tôi thậm chí không đạt ModelState.IsValid khi tôi nhấp vào gửi

+2

Xin vui lòng gửi mẫu-mã của bạn, và hành động mà bạn đang gọi điện thoại để lưu này .. Có vẻ có một số vấn đề với xác nhận, nhưng cần thêm thông tin .... Tại sao câu hỏi này có được một tên xuống bỏ phiếu? –

Trả lời

24

Bạn đã thay đổi bất kỳ tên? Tên của biểu mẫu phải ánh xạ 1-1 với các tham số Hành động của bạn. Trong trường hợp này, tham số "name" không được truyền cho hành động điều khiển, vì vậy nó là null.

hoang dã đoán, cần thêm thông tin (phương pháp chữ ký của hành động)

+10

Ahh yeh ngớ ngẩn tôi đó là vì tôi đã làm điều này ... [Hiển thị (Tên = "")] chuỗi công cộng Addrs {get; bộ; } – Beginner

+0

:) cũng vui vì nó đã được sửa. –

+5

Tôi không chắc chắn nếu nó là cùng một vấn đề nhưng tôi nhận được ngoại lệ tương tự nếu tôi áp dụng một thành viên với một thuộc tính StringLength và cũng áp dụng [DisplayName ("")]. –

2

Nó có lẽ hầu hết có thể là mô hình của bạn có một tài sản mà trả về một giá trị không nullable, như int, DateTime, double vv Và nếu người dùng đang cập nhật mục nhập bạn có thể không lưu trữ giá trị đó trong trường ẩn hoặc ở đâu đó, vì vậy khi dữ liệu được trả về, thuộc tính cụ thể đó là rỗng. Hoặc là nơi mà tài sản vào một lĩnh vực ẩn hoặc làm nullable tài sản của bạn trong một mô hình bằng cách thay đổi int để int ?, vv

16

Bạn sẽ nhận lỗi rằng nếu bạn có một số tính chất trang trí bằng DisplayAttribute với trống Tên ([DisplayAttribute(Name = "", Description = "Any description")])

+0

Không thể tin rằng tôi đã dành một thời gian dài như vậy trước khi đến câu trả lời này. –

10

Nếu bạn sử dụng [Hiển thị (Tên = "")] đối với các thuộc tính của mô hình của bạn, Điều này sẽ gây ra lỗi bạn nhận được. Để giải quyết vấn đề này, bạn nên tránh sử dụng thuộc tính tên hiển thị trống.

[Display(Name = "")] //this line is the cause of error 
public string PromotionCode { get; set; } 
Các vấn đề liên quan