$就岗位MVC控制器返回内部服务器错误:参数字典包含空条目 [英] $.ajax post to MVC controller returns Internal Server Error: Parameters dictionary contains null entry
问题描述
参数词典共包含参数无效项非可空类型'System.Int32'的'APPID'的方法'System.Web.Mvc.ContentResult CheckForInstaller(Int32)已'在'HLIT_TicketingMVC.Controllers.TicketController。一个可选参数必须是引用类型,可空类型,或声明为可选参数。
The parameters dictionary contains a null entry for parameter 'appId' of non-nullable type 'System.Int32' for method 'System.Web.Mvc.ContentResult CheckForInstaller(Int32)' in 'HLIT_TicketingMVC.Controllers.TicketController'. An optional parameter must be a reference type, a nullable type, or be declared as an optional parameter.
function SubmitAjax(url, message, successFunc, errorFunc) {
$.ajax({
type:'POST',
url:url,
data:message,
contentType: 'application/json; charset=utf-8',
dataType: 'json',
success:successFunc,
error:errorFunc
});
};
该数据对象被构建为如下:
The data object is built as follows:
var message={"appId":application.val()};
我也尝试了jsonified字符串:
I have also tried a jsonified string:
var message="{'appId':"+application.val()+"}";
和
var message="{'appId':'"+application.val()+"'}";
我验证了消息即将通过与适当的int值尝试发布之前。在调试鼠标最近发现: {APPID =6}
在控制器上的方法签名是:
The method signature on the controller is:
public ContentResult CheckForInstaller(int appId)
当我删除方法签名的参数,但它遇到断点里面,所以它或者签名需要某种属性或邮件没有正确建立,我相信。
When I remove the parameter from the method signature, it does hit the breakpoint inside, so it's either the signature needing attributes of some kind, or the message isn't built properly I believe.
推荐答案
删除此:
contentType: 'application/json; charset=utf-8',
MVC是不会给JSON解析成 INT
。你想要的默认值应用程序/ x-WWW的形式urlen codeD
。
这篇关于$就岗位MVC控制器返回内部服务器错误:参数字典包含空条目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!