我的观点如下,
class MyModel
{
...
public IDictionary<string, string> Values {get; set;}
}
@model web.Models.MyModel
@{
// This works
if(Model.Values.ContainsKey("key"))
{
// ta daa
}
// If I include this part, I don't even get to reach the previous code
// because the excpetion is thrown
if(Model.Values.TryGetValue("key", out string myValue))
{
}
}
问题是如果我包含TryGetValue
部分,我甚至不能在我的视图中执行任何代码,因为在我登陆视图之前会抛出异常。
错误如下:
An error occurred during the compilation of a resource required to process
this request. Please review the following specific error details and modify
your source code appropriately.
/Views/MyView.cshtml
Syntax error, ',' expected
if(Model.Values.TryGetValue("key", out string myValue)) <-- I don't see any syntax error