This question is locked. New answers and comments are not allowed.
Hi- I am scratching my head as to why I can't get entity data when making a POST using jQuery. I'm using the Sample Application from the Sample Kit. WebAPIKendoUI.11 and when I try to extend the Categories controller with this code:
jQuery:
I get the 400 status codes on both PUT and POST.
Is there something I'm missing? I followed the steps in the tutorial as well and it just isn't working for me. Any direction would be great!!
using System;using System.Collections.Generic;using System.Linq;using System.Net;using System.Net.Http;using System.Web;using System.Web.Http;using WebAPIKendoUI.DataLayer;namespace WebAPIKendoUI.Web.Controllers{ public partial class CategoriesController { /// <summary> /// Updates single entity. /// </summary> /// <remarks>Replaces the whole existing entity with the provided one</remarks> /// <param name="entity">Entity with the new updated values</param> public virtual HttpResponseMessage Put(Category entity) { var modelState = this.ModelState; if (entity == null) { throw new HttpResponseException(HttpStatusCode.BadRequest); } return this.Put(entity.CategoryID, entity); } /// <summary> /// Create single entity. /// </summary> /// <remarks>Creates new car</remarks> /// <param name="entity">Car entity</param> /// <returns>HttpStatusCode.MethodNotAllowed if Car is invalid /// or HttpStatusCode.NoContent if the operation was successful</returns> public virtual HttpResponseMessage Create(Category entity) { if (entity == null) throw new HttpResponseException(HttpStatusCode.BadRequest); this.Post(entity); return Request.CreateResponse(HttpStatusCode.NoContent); } }}jQuery:
$('.update').click(function () { $.ajax({ url: "/api/categories/Put", type: "PUT", contentType: "application/json", success: function (result) { //setMarkers(map, result.d); console.log(result); }, data: { CategoryID: 1, CategoryName: 'tester', ImageFileName: 'test.png' }, error: function (xhr, desc, err) { if (xhr.status == 400) { // BadRequest alert('400'); } else if (xhr.status == 409) { // Conflict alert('409'); } } });})$('.create').click(function () { $.ajax({ url: "/api/categories/Create", type: "POST", contentType: "application/json", success: function (result) { //setMarkers(map, result.d); console.log(result); }, data: { CategoryID: '', CategoryName: 'tester', ImageFileName: 'test.png' }, error: function (xhr, desc, err) { if (xhr.status == 400) { // BadRequest alert('400'); } else if (xhr.status == 409) { // Conflict alert('409'); } } });I get the 400 status codes on both PUT and POST.
Is there something I'm missing? I followed the steps in the tutorial as well and it just isn't working for me. Any direction would be great!!