![](/img/trans.png)
[英]ASP.Net MVC calling a controller action from FullCalendar's javascript function not loading the view
[英]Getting data from javascript function on to ASP.NET MVC Controller's Action Method
我查看了许多关于SO的帖子,以弄清楚我的处境,但收效甚微。 我试图将数据从javascript函数(DropdownChange())发送到MVC控制器Action方法,作为基于在视图上选择的下拉值的参数。 这是我的代码:
在.cshtml //下拉菜单中的代码.... /之后是用于创建新计划的代码
<a href="@Url.Action("ActionMethod")">
<i class="sth" id="sth" Title="Create"></i>
</a>
在.JS文件中,用于获取下拉更改值的函数
function DropdownChange(){
var Value = parseInt($("#dropDownId").val());
$.ajax({
type: "POST",
url: '@ Url.Action("ActionMethod", "Home")',
contentType: 'application/json; charset=utf-8',
dataType: "json",
data: {data : JSON.Stringify(Value)},
success: function (data) {
alert('success');
},
error: error: function (result){
alert('error');
}
});
这是我的Controller操作方法
[HttpPost]
public ActionResult ActionMethod(string Value)
{
// do something with Value
}
我得到的只是一条错误警报消息和一个JS运行时错误以及Value参数的空值。 在这种情况下,谁能帮助我。 提前致谢。
尝试
$.ajax({
type: "POST",
url: '@ Url.Action("ActionMethod", "Home")',
contentType: 'application/json; charset=utf-8',
dataType: "json",
data: JSON.stringify({data: Value}),
success: function (data) {
alert('success');
},
error: error: function (result){
alert('error');
}
});
要么
$.ajax({
type: "POST",
url: '@ Url.Action("ActionMethod", "Home")',
contentType: 'application/json; charset=utf-8',
dataType: "json",
data: Value,
success: function (data) {
alert('success');
},
error: error: function (result){
alert('error');
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.