多个子字符串在 MVC Razor 视图中不起作用

Multiple Substring is not working in MVC Razor view

在下面的 razor 视图中 For Each using

 @foreach (var i in (List<MyDME.Data.Model.ERNFileRequestDTO>)ViewBag.lst)
                    {
                        for (int j = 0; j < i.Parse835Details.storedChkNo.Count; j++)
                        {

                            <tr>
                                <td>
                                    @i.Parse835Details.storedPayorName[j]
                                </td>
                                <td>
                                    @i.Parse835Details.storedChkNo[j]
                                </td>
                                <td>
                                    @i.Parse835Details.storedTotalBilled[j]

                                </td>
                                <td>
                                    @i.Parse835Details.storedTotalPaid[j]

                                </td>
                                <td>
                              //below line doing substring which is not working
   @(i.Parse835Details.storedChkDate[j].Substring(4, 5) + " " + i.Parse835Details.storedChkDate[j].Substring(6, 7) + " " + i.Parse835Details.storedChkDate[j].Substring(0, 3))
                                   
                                </td>
                                <td>
                                    <a href='/PatientManagement/DownloadUploadedDocument?fileName=@Html.Raw(i.path)'>Download</a>

                                </td>
                            </tr>

出现以下错误

System.ArgumentOutOfRangeException: 'Index and length must refer to a location within the string. Parameter name: length'

IF i.Parse835Details.storedChkDate[j] vlaues 是 20210225 就像日期格式在字符串中一样,从这个值做子字符串但不能为多个子字符串做子字符串。

如果我使用低于单一范围,那么它的工作

@i.Parse835Details.storedChkDate[j].Substring(0, 5)

如果我使用低于单个范围,则它不起作用

@i.Parse835Details.storedChkDate[j].Substring(4, 5)

您正在使用方法public string Substring (int startIndex, int length)
不过你好像觉得是public string Substring (int startIndex, int endIndex).

提取字符4+5,需要传length为2,如下:

@i.Parse835Details.storedChkDate[j].Substring(4, 2)

其他调用也类似。