I am trying to render a Razor html Partial view based on a ViewBag condition, but I always get compliation 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
You need to cast ViewBag.Auth
to boolean
@if ((bool)ViewBag.Auth)
{
@{ Html.RenderPartial("_ShowUserInfo"); }
}
Also you need to use @{ }
syntax with RenderPartial
Try using like this..
@if (ViewBag.Auth)
{
@{ Html.RenderPartial("_ShowUserInfo") }
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With