用户代码未处理InvalidOperationException

时间:2011-10-14 23:32:50

标签: .net asp.net-mvc vb.net asp.net-mvc-3 asp.net-mvc-validation

我正在尝试保存对函数列表(xxx)所做的更改...我是否因为它在UpdateModel(e)上的barf并且说:

System.InvalidOperationException was unhandled by user code
Message=The model of type 'xxxxxxx.attendance' could not be updated.
Source=System.Web.Mvc
StackTrace:
   at System.Web.Mvc.Controller.UpdateModel[TModel](TModel model, String prefix, String[] includeProperties, String[] excludeProperties, IValueProvider valueProvider)
   at System.Web.Mvc.Controller.UpdateModel[TModel](TModel model)
   at xxxxxxx.xxxxxxxx.AdminController.ClassAttendance(List`1 attendance) in c:\users\bryan\documents\visual studio 2010\Projects\xxxx\xxxxxxx\Controllers\AdminController.vb:line 1207
   at lambda_method(Closure , ControllerBase , Object[] )
   at System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters)
   at System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters)
   at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters)
   at System.Web.Mvc.ControllerActionInvoker.<>c__DisplayClass15.<InvokeActionMethodWithFilters>b__12()
   at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation)
   InnerException: 

我的功能如下:

    <AcceptVerbs(HttpVerbs.Post)>
    Function ClassAttendance(ByVal attendance As List(Of attendance)) As ActionResult
        For Each attendee In attendance
            Dim item = attendee
            Dim e = db.attendances.Single(Function(t) t.id = item.id)
            Dim _Class_Ref As String = item.course_ref
            Dim _Comments As String = item.Comments
            Dim _Course_Status As String = item.Completed_Class
            If Not String.IsNullOrEmpty(_Comments) Then
                e.Comments = _Comments
            End If

            e.Completed_Class = _Course_Status
            UpdateModel(e)
            db.SaveChanges()
        Next


        Return RedirectToAction("Index")
    End Function

这个功能在???

出错了

1 个答案:

答案 0 :(得分:1)

你切断了InnerException,这可能是其中的原因! : - )

最有可能的是,验证失败了。您可以使用TryUpdateModel来优雅地处理此问题。