When I use @RenderBody
on a view (not principal), I receive this message Error: The file "~/Views/Shared/_Sistema.cshtml" cannot be requested directly because it calls the "RenderBody" method
.
I do not understand it as I am a novice in MVC.
What do I can do?
Thanks!
If you are using the Renderbody
in _Sistema.cshtml file, then make it as a Layout page.
And add another partial page named like MyPartial.cshtml with Layout name as _Sistema.cshtml.
Renderbody is supposed to be in the master page only. i.e., Layout page.
So your _Sistema.cshtml page should only contains the following:
@RenderBody()
@RenderSection("scripts", required: false) @*----Optional---*@
Then your your new partial page MyPartial.cshtml should contain the following:
@{
Layout = "~/_Sistema.cshtml";
}
Then use your partial page in your view as follows:
@Html.Partial("MyPartial")
Hope it helps.
RenderBody
is for masters only. This method renders markup of content pages that does not belong to any particular section. If your view calls RenderBody
, two cases are possible:
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