我正在尝试基于ViewBag条件渲染Razor html部分视图,但我总是得到补偿错误。
@{
if (ViewBag.Auth)
{
@Html.RenderPartial("_ShowUserInfo")
}
}
我也试过......
@if (ViewBag.Auth)
{
@Html.RenderPartial("_ShowUserInfo")
}
Error message:
Compiler Error Message: CS1502: The best overloaded method match for
'System.Web.WebPages.WebPageExecutingBase.Write(System.Web.WebPages.HelperResult)'
has some invalid arguments
答案 0 :(得分:6)
您需要将ViewBag.Auth
投射到boolean
@if ((bool)ViewBag.Auth)
{
@{ Html.RenderPartial("_ShowUserInfo"); }
}
此外,您需要在@{ }
RenderPartial
语法
答案 1 :(得分:3)
尝试使用这样的..
@if (ViewBag.Auth)
{
@{ Html.RenderPartial("_ShowUserInfo") }
}