4

我正在尝试基于 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
4

2 回答 2

6

你需要投射ViewBag.Authboolean

 @if ((bool)ViewBag.Auth)
 {
    @{ Html.RenderPartial("_ShowUserInfo");  } 
 }

您还需要使用@{ }语法RenderPartial

于 2013-11-11T07:19:44.013 回答
3

尝试像这样使用..

@if (ViewBag.Auth)
 {
    @{ Html.RenderPartial("_ShowUserInfo") }
 }
于 2013-11-11T07:22:38.207 回答