0

I am using angular js and doing http get request to get the database records. the http request hit the apiodata controller and get the database records correctly but its returning Failed to load resource: the server responded with a status of 406 (Not Acceptable) . please help me to resolve this. i am testing this using fiddler also. return 406.

model

public class Blog
{
    public int BlogId { get; set; }
    public string Name { get; set; }
   [JsonIgnore]
    public virtual List<Post> Posts { get; set; }
}
public class Post
{
    public int PostId { get; set; }
    public string Title { get; set; }
    public string Cotent { get; set; }

    public int BlogId { get; set; }
     [JsonIgnore]
    public virtual Blog Blog { get; set; }
}

angular js controller js

aboutmeApp.controller("oDataCRUDController", function ($scope, $http) {
$scope.ShowPosts = function () {

    $http({
        method: 'GET',
        url: 'odata/BlogoData',
        headers: { 'Content-Type': 'application/json' }
    }).success(function (data) {

        $scope.result = data;

    })
}
});

oData API controller

 public class BlogoDataController : ODataController
{
    private BlogDB db = new BlogDB();

    // GET odata/BlogoData

    public List<Post> GetBlogoData()
    {
        var result = db.Posts.ToList();
        return result.ToList();
    }
 }
  • Are you sure the url is correct? Maybe try to access the url directly from the browser to make sure it's returning a json response – azium May 01 '15 at 01:17
  • below out put i got when i use the url - http://localhost:61186/odata/ { "@odata.context":"http://localhost:61186/odata/$metadata","value":[ { "name":"BlogoData","kind":"EntitySet","url":"BlogoData" },{ "name":"Blogs","kind":"EntitySet","url":"Blogs" } ] } when I use http://localhost:61186/odata/BlogoData, its hitting the api controller correctly and its access the database records but while returning i got 406 error. please help me – Jegatheeswaran Andiappan May 01 '15 at 08:39
  • What happens if you follow this and add a CORS header in your web.config? http://enable-cors.org/server_iis7.html – azium May 01 '15 at 13:45
  • there is no luck i got the same 406 error – Jegatheeswaran Andiappan May 01 '15 at 19:59
  • Possible duplicate of [SO-26676879](http://stackoverflow.com/questions/26676879/webapi-and-odatacontroller-return-406-not-available) or [SO-12643176](http://stackoverflow.com/questions/12643176/using-c-sharp-web-api-with-alternate-content-type)? – CrnaStena May 04 '15 at 17:52

0 Answers0