Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-mvc/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net mvc $.ajax发送到MVC控制器返回内部服务器错误:参数字典包含空条目_Asp.net Mvc_Jquery - Fatal编程技术网

Asp.net mvc $.ajax发送到MVC控制器返回内部服务器错误:参数字典包含空条目

Asp.net mvc $.ajax发送到MVC控制器返回内部服务器错误:参数字典包含空条目,asp.net-mvc,jquery,Asp.net Mvc,Jquery,参数字典包含“HLIT_TicketingMVC.Controllers.TicketController”中方法“System.Web.Mvc.ContentResult CheckForInstaller(Int32)”的非null类型“System.Int32”的参数“appId”的null条目。可选参数必须是引用类型、可为null的类型或声明为可选参数 function SubmitAjax(url, message, successFunc, errorFunc) { $.ajax

参数字典包含“HLIT_TicketingMVC.Controllers.TicketController”中方法“System.Web.Mvc.ContentResult CheckForInstaller(Int32)”的非null类型“System.Int32”的参数“appId”的null条目。可选参数必须是引用类型、可为null的类型或声明为可选参数

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
  });
};
数据对象的构建如下所示:

var message={"appId":application.val()};
我还尝试了jsonified字符串:

var message="{'appId':"+application.val()+"}";

在尝试发布之前,我验证了消息是否具有正确的int值。鼠标悬停在调试器上最近显示:
{appId=“6”}

控制器上的方法签名为:

public ContentResult CheckForInstaller(int appId)

当我从方法签名中删除参数时,它确实击中了内部的断点,因此我认为要么是签名需要某种属性,要么是消息没有正确构建。

我认为可能是您正在向控制器发送json试试这个

function SubmitAjax(url, message, successFunc, errorFunc) {
  $.ajax({
    type:'POST',
    url:url,
    data:"appId=" + application.val(),//not sure where you get the value from in your current code  
    dataType: 'json',
    success:successFunc,
    error:errorFunc
  });
};
删除此项:

contentType: 'application/json; charset=utf-8',

MVC不会将JSON解析为
int
。您需要默认值
application/x-www-form-urlencoded

将int更改为字符串时是否得到任何结果:public ContentResult CheckForInstaller(string appId)?该应用程序对象是什么?你确定它按预期工作吗?@ağdaş-是的,当我将鼠标悬停在结果上时,它会显示我预期的值。@Pbirkoff-我没有尝试,但发现了问题,下面的答案被接受。在这种情况下,我们是否必须为将被调用的操作方法定义一个特殊的路由?还是自动绑定?@lordcolve:不,你不需要特殊路线。在这种情况下,我们是否必须为要调用的操作方法定义一个特殊的路由?还是自动绑定?
contentType: 'application/json; charset=utf-8',