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
没有评论:
发表评论