Javascript代码:
var x = null;
var action_data = {x:x};
$.get(
'~/MyController/MyAction',
action_data,
function(result){
//do_something
}
);
控制器操作:
public class MyController: Controller{
...
public ActionResult MyAction(string x)
{
//here, x is the string 'null';
}
}
有人可以向我解释为什么字符串“null”被发送到操作而不是值null?感谢
答案 0 :(得分:1)
因为你传递了数据null,它转换为字符串并设置为你的行动:
var x = null;
x="any thing"; // you need to change x value to be sent here
var action_data = {x:x};
$.get(
'~/MyController/MyAction',
action_data,
function(result){
//do_something
}
);
如果你想传递null:
var x;
var action_data = {x:x};
$.get(
'~/MyController/MyAction',
action_data,
function(result){
//do_something
}
);
答案 1 :(得分:0)
好的,感谢Ahmed,我提出了解决方案:
var x; //without the null initialization
诀窍;)