TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Asit Singh
NA
547
408.2k
Why I am getting the 500 error only when I am posting the da
Mar 13 2016 3:44 AM
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>
Reply
Answers (
1
)
How to set position of div in asp.net as in design page
Autocomplete Dropdown is not working in mvc4?