Reputation: 41
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
Reputation: 41
Thanks all. I have the answer now ... _db.SaveChanges() commits to database.
Upvotes: 0