Why doesn't the Razor HTML Partial View display between the "If" Block?

I try to display the Razor html Partial view based on the ViewBag condition, but always get addition errors.

 @{

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

 }

I also tried ...

 @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
source share
2 answers

You need to drop ViewBag.Authinboolean

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

Also you need to use syntax @{ }withRenderPartial

+6
source

Try using it like this.

@if (ViewBag.Auth)
 {
    @{ Html.RenderPartial("_ShowUserInfo") }
 }
+3
source

All Articles