0

Dears, I have two classes Master and detail named by Raterequest and Raterequestdetails. I have created a viewmodel contains both of them. in Angularjs i have an object contains rate and a list contains orderdetails. when i debug the controller the data received is null for both here is the code

Rate request class

 public class RateRequests
{
    public int RateRequestsID { get; set; }
    public DateTime RateRequestsDate { get; set; }
    public string RateRequestName { get; set; }
    public string RateRequestType { get; set; }
    public string RateRequestMode { get; set; }


}

Rate request details class

public class RateRequestsLines
{
    public int RateRequestsLinesID { get; set; }
    public int RateRequestsID { get; set; }
    [ForeignKey("RateRequestsID")]
    public virtual RateRequests RateRequestsFK { get; set; }
    public short FCLCNTRS { get; set; }
    public short FCLCNTRSSIZE { get; set; }
    public string FCLCNTRSTYPE { get; set; }

}

Rate request view model

public class RateRequestViewModel
{
    public RateRequests rate { get; set; }
    public IEnumerable<RateRequestsLines> ratelines { get; set; }
}

Angularjs

var linkers = angular.module("linkers", [])
.service("linkersSrv", function ($http) {

    var urlBase = "/LinkersEgypt/";

    this.save = function (url, ratee) {
        return $http({
            method: "POST",
            url: urlBase + "/" + url,
            data: ratee,
            ̶a̶s̶y̶n̶c̶:̶ ̶f̶a̶l̶s̶e̶,̶
        })

    };

})
.controller("linkersCon", function ($scope, linkersSrv) {

    $scope.fcl = [];

    $scope.addFCL = function () {
        $scope.fcl.push({ FCLCNTRS: $scope.ncntrs, FCLCNTRSSIZE: $scope.csize, FCLCNTRSTYPE: $scope.ctype });
        console.log($scope.fcl);
    }

    $scope.save = function () {

        var ratee = {
            rate: {
                RateRequestsDate: $scope.rdate,
                RateRequestName: $scope.rname,
                RateRequestType: $scope.rtype,
                RateRequestMode: $scope.smode
            },
            RateRequestsLines: $scope.fcl
        };

        console.log(ratee);
        var promisepost = linkersSrv.save("RateRequest/AddAllRate", ratee);
        promisepost.then(function () {
            toastr.success("Successfully saved");

        })

    }
})

Rate controller

[HttpPost]
    public JsonResult AddAllRate (RateRequestViewModel rate)
    {
        return new JsonResult();
    }

Any help Thanks in advance

8
  • Try adding [FromBody]: AddAllRate ([FromBody] RateRequestViewModel rate), since binding should be performed against request body not request params. Commented Mar 3, 2019 at 17:24
  • check JsonSerializerSettings in project this link Commented Mar 3, 2019 at 18:12
  • [FromBody] is raising an error " Attribute could not be found Commented Mar 3, 2019 at 18:43
  • can you explain more how to check jsonserializer on my code Commented Mar 3, 2019 at 18:50
  • async is not a recognized property of the $http service config object. Commented Mar 3, 2019 at 19:22

0

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.