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
<pre lang="c#">
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; }
}
</pre>
This is the controller Method
<pre lang="c#">
[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);
}
</pre>
this is the Angular js Service
<pre lang="Javascript">
/// <reference path="D:\FetotAdmin\FetotAdmin\FetotAdmin\Scripts/angular.js" />
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));
//var req = $http({
// method: 'post',
// url: urlBase + '/Category',
// data: category
//});
//return req;
return $http.post('http://localhost:60624/api/Category/', category);
};
return CategoryApi;
});
</pre>