0

i am create small demo for getting user list.i am using for this web api with angularjs mvc c#. i am view this list for used jquery datatable with angularjs.

i am trying for view list of user then getting error like this in console "Server Error in '/' Application".

here my angulr.js code:

app.controller('Usercontroller', ['$scope', '$http', 'DTOptionsBuilder', 'DTColumnBuilder',
function ($scope, $http, DTOptionsBuilder, DTColumnBuilder) {
    $scope.dtColumns = [
        //DTColumnBuilder.newColumn("id", "User ID"),
        DTColumnBuilder.newColumn("firstname", "First Name"),
        DTColumnBuilder.newColumn("lastname", "Last Name"),           
    ]
    $scope.dtOptions = DTOptionsBuilder.newOptions().withOption('ajax', {
        url: "/User/GetUsers",
        type: "GET"
    })
    .withPaginationType('full_numbers')
    .withDisplayLength(10);
}])

here my controller code:

 [HttpGet]
    public IHttpActionResult GetUsers()
    {
        return Json(db.Users.ToList());
    }

i don't know where is my mistake any one know then please let me know.

2
  • Are you sure you are getting a 404? Have you tried putting a breakpoint in the controller action and seeing what happens there? Commented Mar 4, 2017 at 11:24
  • @juunas my brekpoint is not stop in controller i don't know why? Commented Mar 5, 2017 at 4:30

1 Answer 1

0

First access get method of web API by hitting the web api url in browser

try to give full URL of the Web API from where you are trying to get users list.

var ajaxURL = window.location.href.substring(0, window.location.href.lastIndexOf("/") + 1) + 'API/User/GetUsers;

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.