Click here to Skip to main content
15,898,222 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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


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; }
  }



This is the controller Method

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);
     }



this is the Angular js Service

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;

});


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
Posted
Updated 12-Mar-16 21:53pm

1 solution

Do you have Fiddler installed? If so - you may see a better error explanation in the response.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900