我正在尝试根据 ViewBag 条件呈现 Razor html Partial View ,但我总是遇到编译错误。
@{
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
最佳答案
您需要投 ViewBag.Auth
至 boolean
@if ((bool)ViewBag.Auth)
{
@{ Html.RenderPartial("_ShowUserInfo"); }
}
您还需要使用
@{ }
与 RenderPartial
的语法
关于asp.net-mvc-4 - 为什么 Razor HTML Partial View 没有在 'If' block 之间呈现?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19900817/