邮递员POST工作正常,但AngularJS帖子抛出404

时间:2018-07-16 16:48:04

标签: angularjs asp.net-web-api

我只是试图通过AngularJS $ http将一些基本表单数据传递到Web-api。

以下是用于将数据发送到API的函数:

    $http({
        url: "/Portal/GenerateTimeSheets",
        method: "POST",
        headers: {
            'Content-Type': 'application/json'
        },
        data: angular.toJson($scope.placementForm),
    }).then(function (response) {

    }), function(response) {

    };

注意:如果我断点并将$ scope.placementForm数据复制并粘贴到邮递员中,则可以正常工作,但是通过浏览器抛出错误。

这是我的api:

   [HttpPost]
    public void GenerateTimeSheets([FromBody]PlacementModel placement)
    {
        Console.WriteLine("STUB");
    }

和展示位置模型:

    [JsonProperty(PropertyName = "candidateName")]
    public string CandidateName { get; set; }

    [JsonProperty(PropertyName = "clientName")]
    public string ClientName { get; set; }

    [JsonProperty(PropertyName = "jobTitle")]
    public string JobTitle { get; set; }

    [JsonProperty(PropertyName = "placementStartDate")]
    public string StartDate { get; set; }

    [JsonProperty(PropertyName = "placementEndDate")]
    public string EndDate { get; set; }

    [JsonProperty(PropertyName = "frequency")]
    public string TimeSheetFrequency { get; set; }

1 个答案:

答案 0 :(得分:1)

404通常表示请求的URL错误,您在URL中丢失了一些内容。使用后端验证您的网址。希望对您有帮助