问题描述
我正在从Angular向控制器发送一个恰好是字符串的值。但它在控制器中变为空。我在其他一些模块中也这样做了,一切都很好。但是我无法在下面的代码中找出问题..请帮助......
这是我的控制器:
[HttpPost]
public JsonResult OpenNewDay(string dayopen)
{
string Messege = sessionservice。 Newday(dayopen);
返回Json(Messege,JsonRequestBehavior.AllowGet);
}
这是我的视图和Angular:
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:
< form class =form-inline >
<form class="form-inline">
< label class =sr-only>会话开放日期&L t; / label>
< input type =textng-model =dayopenreadonly =readonlyclass =form-control>
<label class="sr-only">Session Open Date</label>
<input type="text" ng-model="dayopen" readonly="readonly" class="form-control">
< button type =buttonng-click =保存(dayopen)class =btn btn-default>打开< /按钮>
< / form>
<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({
方法:POST,
url:/ Session / OpenNewDay,
数据:JSON.stringify(dayopen),
})。成功(功能on(data){
alert(data);
})。error(function(err){
$ scope.Message = err 。消息;
})
};
});
< / script>
<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>
推荐答案
这篇关于在使用Angular时如何从视图向控制器发送数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!