[英]Getting “The parameters dictionary contains a null entry for parameter 'ID' of non-nullable type 'System.Int32' for method X” in C#
When I run this command from my view in exceptions.html
当我在
exceptions.html
中从我的视图中运行此命令时。html
<tr ng-repeat="scbEXCEPtions in vm.scbExpData">
<td>
<button class="btn btn-alert btn-xs" ng-click="vm.DelExceptionObjRef(scbEXCEPtions.REF_ID)">
Remove
</button>
</td>
</tr>
and in my controller file exception.js
, this is the method I call在我的 controller 文件
exception.js
中,这是我调用的方法
vm.DelExceptionObjRef = function (refno) {
vm.viewModelHelper.apiGet('api/scbexception/RevertExceptionById/' + refno, null,
function (result) {
vm.prepareData(result.data);
},
function (result) {
toastr.error(result.data, 'Fintrak');
}, null);
}
which generates this URL when clicked on, even after setting a breakpoint on the apicontroller file, I get this error:单击它会生成此 URL,即使在 apicontroller 文件上设置断点后,我也会收到此错误:
http://localhost:6861/api/scbEXCEPtion/RevertExceptionById/10000011943
and I have a method in my Api Controller { ScbExceptionApiController
} that receives the function and method here...我在我的 Api Controller {
ScbExceptionApiController
} 中有一个方法,它接收 function 和这里的方法......
[HttpGet]
[Route("RevertExceptionById/{ID}")]
public HttpResponseMessage RevertExceptionById(HttpRequestMessage request, int ID){
return GetHttpResponse(request, () => {
HttpResponseMessage response = null;
ScbException[] scbexception = _APPModuleService.RevertExceptionById(ID);
response = request.CreateResponse<ScbException[]>(HttpStatusCode.OK, scbexception);
return response;
});
}
but after execution I get this error, and I don't understand why但执行后我得到这个错误,我不明白为什么
{"Message":"The request is invalid.","MessageDetail":"The parameters dictionary contains a null entry for parameter 'ID' of non-nullable type 'System.Int32' for method 'System.Net.Http.HttpResponseMessage RevertExceptionById(System.Net.Http.HttpRequestMessage, Int32)' in 'Fintrak.Presentation.WebClient.API.ScbExceptionApiController'. An optional parameter must be a reference type, a nullable type, or be declared as an optional parameter."}
RevertExceptionById(HttpRequestMessage request, int ID)
is expecting ID
as an int
, which is a 32-bit integer. RevertExceptionById(HttpRequestMessage request, int ID)
期望ID
为int
,即 32 位 integer。
The max value of a 32-bit integer is 2147483647
. 32 位 integer 的最大值为
2147483647
。 You're passing 10000011943
as the ID, which is exceeding this max value.您将
10000011943
作为 ID 传递,它超过了这个最大值。
I suspect this is the reason the parameter binding for ID
is failing with the given exception.我怀疑这是
ID
的参数绑定因给定异常而失败的原因。
Possible solutions could be: use lower ids, or use string
instead of int
for the ID.可能的解决方案可能是:使用较低的 id,或使用
string
而不是int
作为 ID。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.