我在下面的代码中花了2个小时跟踪语法错误。可能是什么问题
<div id="generalError">
<div>
@{if (System.Web.HttpContext.Current.Session["statusCode"].ToString() == "500")
{
<img src="~/Content/Images/oops.png" />
}
else if (System.Web.HttpContext.Current.Session["statusCode"].ToString() == "404")
{
<img src="~/Content/Images/sad.png" />
}
else if (System.Web.HttpContext.Current.Session["statusCode"].ToString() == "401")
{
<img src="~/Content/Images/authError.png" />
}
else if (System.Web.HttpContext.Current.Session["statusCode"].ToString() == "419" || System.Web.HttpContext.Current.Session["statusCode"].ToString() == "408")
{
<img src="~/Content/Images/oops.png" />
}
else
{
<img src="~/Content/Images/oops.png" />
}
}
</div>
<div style="display:inline-block;vertical-align:top;width:600px;padding-left:50px;">
<div style="color:#fff;font-size:36px;font-family:'Segoe UI Light'">
Sorry, something went wrong.
</div>
<div style="color:#fff;font-size:16px;font-family:'Segoe UI';padding-top:12px;padding-bottom:5px;">
@if (System.Web.HttpContext.Current.Session["statusCode"].ToString() == "500")
{
@Html.Raw(System.Web.HttpContext.Current.Session["errorMessage"].ToString());
}
else if (System.Web.HttpContext.Current.Session["statusCode"].ToString() == "419" || System.Web.HttpContext.Current.Session["statusCode"].ToString() == "408")
{
@: Timeout error.
}
else if (System.Web.HttpContext.Current.Session["statusCode"].ToString() == "404")
{
@: Page not found.
}
else if (System.Web.HttpContext.Current.Session["statusCode"].ToString() == "403")
{
@: Forbidden.
}
else if (System.Web.HttpContext.Current.Session["statusCode"].ToString() == "401")
{
@: Unauthorized error.
}
else
{
@Html.Raw(System.Web.HttpContext.Current.Session["errorMessage"].ToString());
}
</div>
</div>
</div>
答案 0 :(得分:2)
只需删除&#34; {&#34;介于@和if ...
之间 @{if ==> @if