2021年1月16日星期六

.NET Core 3.1 MVC Angularjs - JS passing null parameters to Controller

I'm having problem passing parameters from js to controller. This is my code:

SuperAdminCotroller.js

$mdDialog.show(confirm).then(function () {       $scope.ShowSaving();       $http({            method: "post",            url: "/Employee/AddNewEmployee",            datatype: "json",            data: JSON.stringify($scope.Emp),            headers: { "Content-Type": "application/json" }        }).then(function (response) {            $scope.savePresentAddress();            $scope.savePermanentAddress();            $scope.addNewEmployeeEducationalBackgroundRecord();            $scope.addNewEmployeeDependentRecord();            $scope.addEmployeeOnboardingDetails();         }, function (response) {            $scope.ShowInformation('Error', 'Error Occured When Inserting');         });  }  

EmployeeController.cs

[HttpPost]  [Route("/Employee/AddNewEmployee")]  public JsonResult AddNewEmployee([FromBody]Employee Emp)  {       if (Emp != null)       {            using (dbavlincpayrollEntities dbavlincpayroll = new dbavlincpayrollEntities())            {                 Emp.official_time_in = new TimeSpan(9, 0, 0);                 Emp.official_time_out = new TimeSpan(18, 0, 0);                 dbavlincpayroll.Employees.Add(Emp);                 dbavlincpayroll.SaveChanges();                 return Json(Emp);             }        }        else        {             return Json("Some Error Occured");        }  }  

The $scope.Emp can get the parameters from the View upon checking on the debugger. However, it failed to pass into the Controller leaving Emp null values. Project originally created from .NET Framework and was tasked to convert to .NET Core 3.1

https://stackoverflow.com/questions/65756335/net-core-3-1-mvc-angularjs-js-passing-null-parameters-to-controller January 17, 2021 at 09:06AM

没有评论:

发表评论