繁体   English   中英

在 C# 中获取“参数字典包含方法 X 的不可空类型 'System.Int32' 的参数 'ID' 的 null 条目”

[英]Getting “The parameters dictionary contains a null entry for parameter 'ID' of non-nullable type 'System.Int32' for method X” in C#

当我在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>

在我的 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);
   }

单击它会生成此 URL,即使在 apicontroller 文件上设置断点后,我也会收到此错误:

http://localhost:6861/api/scbEXCEPtion/RevertExceptionById/10000011943

我在我的 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;
        });
    }

但执行后我得到这个错误,我不明白为什么

{"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)期望IDint ,即 32 位 integer。

32 位 integer 的最大值2147483647 您将10000011943作为 ID 传递,它超过了这个最大值。

我怀疑这是ID的参数绑定因给定异常而失败的原因。

可能的解决方案可能是:使用较低的 id,或使用string而不是int作为 ID。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM