为什么.NET在表单标记内发生异常时识别错误的行号?这是一个Razor .cshtml文件中的简单测试用例:
@{
string[] test = new string[2];
test[0] = "stuff";
}
@test[0] <br />
<form action="~music/addToCart" method="post">
<input type="text" name="test" value="@test[2]" />
<input type="submit" value="Submit" />
</form>
Run Code Online (Sandbox Code Playgroud)
"索引超出数组范围"的异常显示test[0]实际异常的行test[2].调试器还显示错误的行.似乎在表单标记内发生异常时,表单上方的语句被错误地标识为错误的位置.我已经尝试使用Html帮助程序BeginForm()并得到类似的行为.
使用Microsoft .NET Framework版本:4.0.30319; ASP.NET版本:4.7.2117.0.Visual Studio社区2017.