Skindeep2366
Skindeep2366

Reputation: 1559

InvalidOperationException was unhandled by user code

I am trying to save changes made to a list(of xxx) in a function... Am I over looking something because it barfs on the UpdateModel(e) with saying:

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: 

My function is as follows:

    <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

Where is this function going wrong at???

Upvotes: 1

Views: 3988

Answers (1)

Danny Tuppeny
Danny Tuppeny

Reputation: 42343

You chopped off the InnerException, which probably has the reason in it! :-)

Most likely, it's failing validation or something. You can use the TryUpdateModel to handle this gracefully.

Upvotes: 1

Related Questions