2

I am building an application with the following flow My Controller will call the View. Inside the view i am calling a js file which has angularjs code with makes a call to the APIController.

I am getting the following error :

Request URL:http://localhost:52096/api/EVerify/GetEmployeeList
Request Method:POST
Status Code:404 Not Found

What am i missing or doing wrong.

Controller :

using System.Web.Mvc;

namespace MVC.EVerify.Controllers
{
    [Authorize]
    public class EVerifyController : Controller
    {
        #region Methods
        #region ListEVerify
        public ActionResult ListEVerify()
        {
            if (Request.IsAjaxRequest()) return PartialView();
            return View();
        }
        #endregion
}

View :

In this view on click of a button I am loading another view along with Javascript file which has angular code called EverifyModule.js

<table>
 <tbody>
    <tr ng-repeat="emp in EmployeeInfo">
      <td>{{emp.name}}</td>
       <td>{{emp.hireDate}}</td>
       <td><a class="btn-sm btn-primary pull-right" href="javascript:void(0)"  onclick="LoadViewSelected('/EVerify/EVerify/EVerifySubmit', 'EVerifyModule', 'E-VerifySubmit');">E-Verify</a></td>
     </tr>
  </tbody>
</table>

EVerifyModule.js

var EVerifyModule = angular.module('EVerifyModule', ['angularFileUpload', 'ui.bootstrap', 'angularUtils.directives.dirPagination']);


    EVerifyModule.factory('EVerifyModuleService', ['$http', '$window', function ($http, $window) {

        return {

            GetEmployeeList: function (companyId) {
                return $http({
                    url: '/api/EVerify/GetEmployeeList',
                    method: 'POST',
                    data: companyId
                });
            }
        };
    }]);


    EVerifyModule.controller('EVerifyController', ['$scope', '$http', '$compile', 'EVerifyModuleService', '$modal', '$timeout', function ($scope, $http, $compile, EVerifyModuleService, $modal, $timeout) {

        EVerifyModuleService.GetEmployeeList(58).then(function (response) {
            $scope.EmployeeInfo = response.data.Employees;
        });

EVerifyAPIController :

namespace MVC.EVerify.Controllers
{
    [RoutePrefix("api/EVerify")]
    public class EVerifyAPIController : ApiController
    {
        #region GetEmployeeList

        [HttpPost]
        [Route("GetEmployeeList")]
        public async Task<IHttpActionResult> GetEmployeeList(int CompanyId)
        {
            List<EmployeeBO> employees = new List<EmployeeBO>();

            try
            {
                employees = await EmployeeBL.GetEmployeeList(CompanyId);
            }
            catch
            {
                employees = new List<EmployeeBO>();
            }

            return Ok(new { Employees = employees });
        }

        #endregion

    }
}
0

2 Answers 2

2

The Model Binder expects your CompanyId parameter to be placed in the URI, but you are sending it inside the request body.

Explicitly tell your action method that you are sending the parameter in the body:

public async Task<IHttpActionResult> GetEmployeeList([FromBody] int CompanyId)
Sign up to request clarification or add additional context in comments.

Comments

0

Looks like the GetEmployeeList method takes in a parameter so maybe you just need to pass it a parameter? Like: http://localhost:52096/api/EVerify/GetEmployeeList/1

1 Comment

When I test this using an API client I am getting the following error : { "Message": "No HTTP resource was found that matches the request URI 'localhost:52096/api/EVerify/GetEmployeeList'." "MessageDetail": "No action was found on the controller 'EVerifyAPI' that matches the request." }

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.