0

My javascript method-

visitorApp.controller('LoginController', function ($scope,$http) {
    $scope.submit = function (isValid) {
        if (isValid) {
            var loginModel = {
                UserName: $scope.UserName,
                PassWord: $scope.Password
            };           

        $http.post(
            '/api/VisitorWeb/VerfiyLogin',
            JSON.stringify(loginModel),
            {
                headers: {
                    'Content-Type': 'application/json'
                }
            }
        ).success(function (data) {
            alert("Hi" +data);
            $scope.message = data;
        });


    }
}

});

My web api method -

[HttpPost]
        public UserLoginDomainModel VerifyLogin(UserLoginDomainModel loginModel)
        {
            //do some business logic
            return loginModel;
        }

My webapiconfig file

public static class WebApiConfig
    {
        public static void Register(HttpConfiguration config)
        {
            config.Formatters.JsonFormatter.SupportedMediaTypes.Add(new MediaTypeHeaderValue("text/html"));

            config.MapHttpAttributeRoutes();

            config.Routes.MapHttpRoute(
                name: "DefaultApi",
                routeTemplate: "api/{controller}/{action}"
            );
        }
    }

I am getting 404 response from server.

"NetworkError: 404 Not Found - http://localhost:43516/api/VisitorWeb/VerfiyLogin"

I was try to follow this link POSTing from Angular to .net WebAPI but some how it is not working for me.

Community
  • 1
  • 1
ankur
  • 4,565
  • 14
  • 64
  • 100

1 Answers1

2

I think you have a typo here:

 $http.post(
            '/api/VisitorWeb/VerfiyLogin',
            JSON.stringify(loginModel),
            {
                headers: {
                    'Content-Type': 'application/json'
                }
            }

Your service method is named VerifyLogin and not VerfiyLogin from what I can see.

Admir Tuzović
  • 10,997
  • 7
  • 35
  • 71