0

I am ashamed that I ask so strange question. However, if someone knows what the error is, I'll be really glad!

I've just start learning AngularJS in ASP.NET MVC. To do this I downloaded sample from Microsoft website - CRUD Operations in MVC 5 using WebAPI with AngularJS. I've tried ask where the project is uploaded, but questons will be answered in two-three weeks.

I hope that a lot of people have met this example and solved this problem.

When I click "Save" after editing some person, then I just see infinite image. I waited twenty minutes, but "Friend" is not updated. How can I resolve it? I would like to edit and save Friends.

How can I save the item?

In my view this method should be called:

public HttpResponseMessage Put(int id, Friend friend)
{
   if (!ModelState.IsValid)
   {
      return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
   }
   if (id != friend.FriendId)
   {
      return Request.CreateResponse(HttpStatusCode.BadRequest);
   }

   db.Entry(friend).State = EntityState.Modified;
   try
   {
      db.SaveChanges();
   }
   catch (DbUpdateConcurrencyException ex)
   {
      return Request.CreateErrorResponse(HttpStatusCode.NotFound, ex);
   }
   return Request.CreateResponse(HttpStatusCode.OK);
}

What I see is just infinite loading: enter image description here

However, nothing updates. Just always image is shown. What should I do? Thanks.

1
  • 3
    You need to learn the difference between client side (angular) and server-side (.NET). I can see you're using chrome, fire up the Developer Console and look at the http request. Did it reach the server? If not; check the request on client side. Otherwise; breakpoint on the server and check the posted object and signature of Friend. There is probably a mismatch on property names etc. Commented Mar 5, 2016 at 11:16

1 Answer 1

0

I just deleted id parameter from the signature of:

public HttpResponseMessage Put(Friend friend)

and this worked for me. The whole code snippet:

public HttpResponseMessage Put(Friend friend)
{
   if (!ModelState.IsValid)
   {
      return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
   }

   db.Entry(friend).State = EntityState.Modified;
   try
   {
      db.SaveChanges();
   }
   catch (DbUpdateConcurrencyException ex)
   {
      return Request.CreateErrorResponse(HttpStatusCode.NotFound, ex);
   }
   return Request.CreateResponse(HttpStatusCode.OK);
}

Maybe it helps somebody:).

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.