我在cshtml Razor視圖中遇到了VS2015中的一個奇怪問題。我認爲它一定是Razor的一個bug,但是如果是poss,會感謝一個理智的檢查和一個解決方法的建議。在VS2015中使用ASP.NET MVC Razor時無法識別大括號
此問題是@{}
代碼塊中的花括號不能正確解析。我在foreach
循環中有一個if
語句,如果我使用大括號來包圍if
操作,則會出現編譯錯誤。有趣的是,在else
聲明之後的花括號看起來很好。
這將更容易與VS顏色編碼演示,但在這裏。
這工作:
@{
var nestLevel = 0;
foreach (var t in xmlHelper.GetProperties(asm, ViewBag.xmlType, "root"))
{
var type = @t.Item3.PropertyType;
if (xmlHelper.builtInTypes.Contains(type.ToString()))
<p>@t.Item1 @t.Item2 @t.Item3.PropertyType</p>
else
{
nestLevel++;
}
}
} //VS shows the @{} code block ending here as expected
但是,如果現在我周圍添加if動作大括號,它不會編譯:
@{
var nestLevel = 0;
foreach (var t in xmlHelper.GetProperties(asm, ViewBag.xmlType, "root"))
{
var type = @t.Item3.PropertyType;
if (xmlHelper.builtInTypes.Contains(type.ToString()))
{
<p>@t.Item1 @t.Item2 @t.Item3.PropertyType</p>
}
else
{
nestLevel++;
}
} //VS now incorrectly shows the @{} code block ending here
}
任何想法/建議?
真棒 - 是的,它修復了它。小學生錯誤!謝謝 – ShhTot