Reputation: 139
I have a page where I am validating a condition. if condition true display different page else displays the login page.
@if (sitemaintainmode == "false")
{
<body>
<div class="navbar navbar-default">
<div class="container">
@Html.Partial("_LoginPartial")
</div>
</div>
<div class="container body-content">
@RenderBody()
</div>
@Html.Partial("_Footer")
</script>
</body>
}
else
{
@RenderPage("~/Views/Account/Error.cshtml");
}
But it gives me an error -
The "RenderBody" method has not been called for layout page "~/Views/Shared/_Layout.cshtml".
Upvotes: 1
Views: 1484
Reputation:
You can not ignore
RenderBody()
in your code because might be you use this Layout="~/Views/Shared/_Layout.cshtml"
in your cshtml page.
Create seperate customeErrorPage (View) and Handle your condition in Controller and use return RedirectToAction("Login Or Error") or use return View("Login or Errorpage")
Hope this will help you.
Upvotes: 1
Reputation: 267
You could handle the action result in the controller, making a redirect to Error view in the Account controller or using customError in the web.config. For instance:
<customErrors mode="RemoteOnly" defaultRedirect="~/Home/Error_Generic/" >
<error statusCode="500" redirect="~/Account/Error" />
</customErrors>
Upvotes: 0