Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/301.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/32.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
C# startIndex不能大于字符串的长度。参数名称:startIndex MVC4_C#_Asp.net_Asp.net Mvc 4 - Fatal编程技术网

C# startIndex不能大于字符串的长度。参数名称:startIndex MVC4

C# startIndex不能大于字符串的长度。参数名称:startIndex MVC4,c#,asp.net,asp.net-mvc-4,C#,Asp.net,Asp.net Mvc 4,我只是在生产中遇到了一个错误,而我正在添加已检查为已接收的接收报告上的权重 在我的本地计算机上,此问题不存在。但在生产过程中,会出现以下错误。 我的控制器: public int ReceivingReportWeight { get { if (_ReceivingReportWeight == null && ReceivingReportCount > 0 && ReceivingReportWeight == 0)

我只是在生产中遇到了一个错误,而我正在添加已检查为已接收的接收报告上的权重

在我的本地计算机上,此问题不存在。但在生产过程中,会出现以下错误。

我的控制器:

public int ReceivingReportWeight
{
    get
    {
        if (_ReceivingReportWeight == null && ReceivingReportCount > 0 && ReceivingReportWeight == 0)
        {
            dynamic receivingReportDbView = Database.Open().vw_ReceivingReports;
            List<int> receivedReceivingReports = receivingReportDbView.Select(receivingReportDbView.Id).Where(receivingReportDbView.ProjectId == Id && receivingReportDbView.Received == true).ToScalarList<int>();
            dynamic vwItemsDbView = Database.Open().vw_Items;
            int receivingReportWeight = vwItemsDbView.Select(vwItemsDbView.Weight.Sum()).Where(vwItemsDbView.ModuleId == MODULE_IDS.RECEIVING_REPORT && vwItemsDbView.TransactionId == receivedReceivingReports).ToScalar<int>();
            _ReceivingReportWeight = receivingReportWeight;
        }

        return _ReceivingReportWeight.GetValueOrDefault();
    }
}
public int receiving reportweight
{
得到
{
如果(_ReceivingReportWeight==null&&ReceivingReportCount>0&&ReceivingReportWeight==0)
{
dynamic receivingReportDbView=Database.Open().vw_ReceivingReports;
List receivedReceivingReports=receivingReportDbView.Select(receivingReportDbView.Id)。其中(receivingReportDbView.ProjectId==Id&&receivingReportDbView.Received==true)。ToScalarList();
动态vwItemsDbView=数据库.Open().vw_项;
int receivingReportWeight=vwItemsDbView.Select(vwItemsDbView.Weight.Sum())。其中(vwItemsDbView.ModuleId==模块ID.RECEIVING_报告和&vwItemsDbView.TransactionId==receivedReceivingReports)。ToScalar();
_接收报告权重=接收报告权重;
}
return _ReceivingReportWeight.GetValueOrDefault();
}
}
我的看法

   @if (Model.ReceivingReportWeight > 0) {
        <div class="actions" style="width: 50%; text-align: right;">
            Total Received Weight: @Model.ReceivingReportWeight lbs.
        </div>
   }
@if(Model.ReceivingReportWeight>0){
收到的总重量:@Model.ReceivingReportWeight lbs。
}

当传递到
startIndex
参数的值大于字符串的总长度时,该错误来自类似
子字符串的内容。例如,如果您有一个像
“Just Testing”
这样的字符串,并且您执行了
.Substring(12,1)
,您会得到该异常,因为该字符串只有12个字符长(请记住索引来自
0
,而不是
1
,因此最后一个索引是
11


但是,您的问题中没有包含这样做的代码。因此,该错误是从其他地方引发的。追踪您使用
子字符串的位置,找出索引超过字符串长度的原因。

我只想告诉大家,我收到了与错误指定控件(Captcha控件)属性完全相同的错误

实际上我已经进去了

 Border="1"

引发了上述错误。当我更正属性名时,代码工作得非常好。

生产中返回的字符串值是否为空?我是说,你能检查一下吗!为什么获取
ReceivingReportWeight
是控制器中的一个属性,而不是数据层中的一个函数?
 Border="1"