howDisWorks
howDisWorks

Reputation: 25

Internal Server Error 500 angularjs, mvc HttpPost

When I'm updating a row in the database I get this error: http://snag.gy/975mW.jpg

Since it's a 500 error I'm guessing it's something in my C# code giving me this error, the strange thing is that the database gets updated and nothing crashes. So I'm wondering how I could debug this error? I'm sending the data from angular to a web api.

 $scope.editUser = function () {
            var user = $scope.selectedUser;
            UserService.editUser(user).success(function (data) {
                console.log('Updated', data)
            }).
            error(function () {
                $scope.error = console.log('Something went wrong')
            });
        }


   [HttpPost]
    public User EditUser([FromBody]EditUserModel model)
    {
        var editedUser = db.Users.FirstOrDefault(u => u.UserID == model.UserID);

    editedUser.FirstName = model.FirstName;
    editedUser.LastName = model.LastName;
    editedUser.Email = model.Email;

    db.SaveChanges();
    return editedUser;
}

Upvotes: 0

Views: 1509

Answers (1)

felix-b
felix-b

Reputation: 8498

According to your description, this is a serialization problem of the return value. Try running the server-side web application under Visual Studio debugger, verify that exception settings are set to to break on all managed exceptions, initiate the action from the browser, and see what happens.

Upvotes: 1

Related Questions