I have following loc in one of my view pages:
@* Html.Partial("Form")*@
@{
var role = Convert.ToInt32(Session["Role"]);
if (role == 2)
{
Html.Partial("Form");
}
}
The Html.Partial("Form")
works fine when its outside any if statement and renders everything fine.
But when Inside an if
block it renders nothing, if statements is hit, it’s true, debugger eves reads the function and goes to the Form Partial view
and goes through every line in it but at the end there is not output on the page.
Kindly help
You should use RenderPartial method when you are inside a code block.
Html.RenderPartial("Form");
Html.Partial returns an HtmlString which would be rendered to the page if it wasn't inside a code block. In your case Razor parses your view and returns the result to your code. Since you don't do anything to render it, you don't get the output.
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