Click here to Skip to main content
14,739,359 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I am sending a value from Angular to controller which happens to be a string. But it becomes null in the controller. I did this in some other modules as well and everything was fine there. But i am unable to figure out the problem in the below code.. Please help......

This is my Controller:

[HttpPost]
public JsonResult OpenNewDay(string dayopen)
{
string Messege = sessionservice.Newday(dayopen);

return Json(Messege, JsonRequestBehavior.AllowGet);
}

This is my View along with the Angular:




Open Session



<form class="form-inline">


<label class="sr-only">Session Open Date</label>
<input type="text" ng-model="dayopen" readonly="readonly" class="form-control">


<button type="button" ng-click="Save(dayopen)" class="btn btn-default">Open</button>
</form>





<script type="text/javascript">

var day = angular.module("dayModule", []);

day.controller("dayController", function ($scope, $http) {
$scope.Save = function (dayopen) {
alert(JSON.stringify(dayopen));
$http({
method: "POST",
url: "/Session/OpenNewDay",
data: JSON.stringify(dayopen),
}).success(function (data) {
alert(data);
}).error(function (err) {
$scope.Message = err.Message;
})
};
});


</script>
Posted

1 solution

Please check the below code...


<script type="text/javascript">

var day = angular.module("dayModule", []);

day.controller("dayController", function ($scope, $http) {
$scope.Save = function (dayopen) {
alert(JSON.stringify(dayopen));
    $http({
        method: "POST",
        url: "/Home/OpenNewDay",
        data: JSON.stringify({ "dayopen": dayopen })
    }).success(function(data) {
        alert(data);
    }).error(function(err) {
        alert(err);
    });
};
});


</script>
   
Comments
Member 11579819 13-Dec-15 12:43pm
   
thanks Rajdeep

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900