Pelumi Bodunwa
Pelumi Bodunwa

Reputation: 41

Web API Client Posting Not Hitting Database

Kindly help with ASP.NET MVC 4 Web Api project. I can retrieve JSON from my api controller without hitch, and posting seems to work (my UI is updated), but data is not hitting the database.

// POST api/todoes public HttpResponseMessage Post(Todo item) { item = _db.Todoes.Add(item); var response = Request.CreateResponse(HttpStatusCode.Created, item);

        string uri = Url.Link("DefaultApi", new { id = item.TodoId });
        response.Headers.Location = new Uri(uri);
        return response;
    }

      self.create = function (formElement) {
          // If valid, post the serialized form data to the web api
          //$(formElement).validate();
          //if ($(formElement).valid()) {
              $.post(baseUri, $(formElement).serialize(), null, "json")
                  .done(function (o) { self.todoes.push(o); });
          //}
      }

'Am I doing something wrong?

Upvotes: 0

Views: 225

Answers (1)

Pelumi Bodunwa
Pelumi Bodunwa

Reputation: 41

Thanks all. I have the answer now ... _db.SaveChanges() commits to database.

Upvotes: 0

Related Questions