gpt4 book ai didi

asp.net-mvc - MVC View 从不存在的代码中抛出错误

转载 作者:行者123 更新时间:2023-12-01 22:28:48 26 4
gpt4 key购买 nike

我有一个 Razor 局部 View ,它正在抛出错误,上面写着:

Index (zero based) must be greater than or equal to zero and less than the size of the argument list.

当我查看堆栈跟踪时,我找到了对 String.Format(string, args) 的调用。

问题是在这行代码中没有对 String.Format() 的调用。此外,调试器突出显示了一段代码,其中没有对 String.Format() 的此类调用。

我试过删除临时 Internet 文件。我试过清理和重建。我正在使用 Visual Studio Web Developer Express 2013 Update 4。

这是调试器在抛出错误时的照片(请注意绿色突出显示,以及断点处的红色突出显示 - 似乎正在选择不存在的其他内容):

enter image description here

最佳答案

抛出异常的是以下几行(共4行)

@string.Format("1_{1}", i)

应该是

@string.Format("1_{0}", i)

您只需向 string.Format() 提供一个参数,它对应于内部参数数组的索引 0。考虑以下代码:

    public static string Format(string format, params object[] args);

这是 string.Format() 的 BCL 签名,请注意“args”参数是如何声明为数组的。 params 关键字仅允许语法糖从消费者代码中隐藏数组。 format itemsformat string 中表示该数组中从 0 开始的索引。

引用资料

关于asp.net-mvc - MVC View 从不存在的代码中抛出错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30541638/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com