Hi I am trying to post data to web api I am getting 500 error and method is not being called . The code is below
This is the Model class
public class Category
{
public int CategoryId { get; set; }
public string CategoryName { get; set; }
public string ParentCategoryId { get; set; }
public string IsServiceContainer { get; set; }
public string ImageUrl { get; set; }
public string Description { get; set; }
public List<Category> ChildCategories { get; set; }
public string IsActive { get; set; }
}
This is the controller Method
[ResponseType(typeof(Category))]
public IHttpActionResult PostCategory(Category category)
{
if (!ModelState.IsValid)
{
return BadRequest(ModelState);
}
ObDataAccess.InsertCategory(category.CategoryName, category.ImageUrl, category.ParentCategoryId, category.IsActive, category.Description, category.IsServiceContainer);
return CreatedAtRoute("DefaultApi", new { id = category.CategoryId }, category);
}
this is the Angular js Service
var CategoryService = angular.module('CategoryService', []);
CategoryService.factory('CategoryApi', function ($http) {
var urlBase = "http://localhost:60624/api";
var CategoryApi = {};
CategoryApi.getCategorees = function () {
return $http.get(urlBase + '/Category');
};
CategoryApi.AddCategory = function (category) {
alert(JSON.stringify(category));
return $http.post('http://localhost:60624/api/Category/', category);
};
return CategoryApi;
});
What I have tried:
I tried with $http.post method. when I am calling the web api created with Entity framework it is working fine but when I am calling self created web api with post operation its giving 500 error only in case of post data