Press Ctrl / CMD + C to copy this to your clipboard.
Copied to clipboard
Flag this post as spam?
This post will be reported to the moderators as potential spam to be looked at
Topic author was deleted
Oct 08, 2016 @ 16:09
The file "~/Views/Master.cshtml" cannot be requested directly because it calls the "RenderBody" method.
I don't really understand this error and I am having a rough time. I want to use RenderBody() method to load subpages like contact, about, etc, upon being clicked in the navigation bar.
Another note: I do not understand the reason why I cannot add @model to my master page, why can't I do that but have to create two extra partial pages when creating a contact form.
In MVC, whenever a view has a RenderBody-method it's a template view. Template views can't be request/presented by itself. It needs a subview to be rendered (where you wrote "RenderBody()") to make up a valid page.
If you want to display only the template view, you need to make a empty subview that uses this template view as its layout. This subview cannot be a template view (call a RenderBody-method) itself.
On your second note: I belive you can reference your model in UmbracoTemplatePage. Try moving line #2 (the @using-line) above the @inherits-line and see if that doesn't fix your problem - the variable of "ContentModels" is unknown to line #1 because it isn't defined untill line #2 :)
Hey Dennis I feel like I understand what you are saying but I am still receiving this error.
Here is an index.html that I was to be replaced (loaded into) RenderBody(); in my Master.cshtml which is my template/layout.
This is my index.cshtml which inherits to layout Master.cshtml which is my template (layout page). I entered "RenderBody()" strictly into the Master.cshtml with the goal of having Index.cshtml being load into it by default.
And I am still receiving this error. I do not want two layouts, just one which will be Master.cshtml. Thank you!
I receive the following error . "cannot be requested directly because it calls the "RenderBody()" method" and the same for RenderSection(). Can anyone help me ?
If there's something I need explaining again please ask (I know I might not have explained it very well).
But the way around this problem is basically to either remove the "RenderBody()" or call the template that inherits from the layout you're trying to call - since you cannot call that page directly.
Topic author was deleted
The file "~/Views/Master.cshtml" cannot be requested directly because it calls the "RenderBody" method.
I don't really understand this error and I am having a rough time. I want to use RenderBody() method to load subpages like contact, about, etc, upon being clicked in the navigation bar.
Another note: I do not understand the reason why I cannot add @model to my master page, why can't I do that but have to create two extra partial pages when creating a contact form.
Thank you!
In MVC, whenever a view has a RenderBody-method it's a template view. Template views can't be request/presented by itself. It needs a subview to be rendered (where you wrote "RenderBody()") to make up a valid page.
If you want to display only the template view, you need to make a empty subview that uses this template view as its layout. This subview cannot be a template view (call a RenderBody-method) itself.
For more: http://stackoverflow.com/questions/17368464/trying-to-use-two-layout-pages-on-mvc4-and-razor
On your second note: I belive you can reference your model in UmbracoTemplatePage. Try moving line #2 (the @using-line) above the @inherits-line and see if that doesn't fix your problem - the variable of "ContentModels" is unknown to line #1 because it isn't defined untill line #2 :)
Comment author was deleted
Hey Dennis I feel like I understand what you are saying but I am still receiving this error.
Here is an index.html that I was to be replaced (loaded into) RenderBody(); in my Master.cshtml which is my template/layout. This is my index.cshtml which inherits to layout Master.cshtml which is my template (layout page). I entered "RenderBody()" strictly into the Master.cshtml with the goal of having Index.cshtml being load into it by default.
And I am still receiving this error. I do not want two layouts, just one which will be Master.cshtml. Thank you!
Comment author was deleted
Hey actually I think the best thing to do right now would be to watch the umbraco.tv episodes.
Hi Everyone,
I receive the following error . "cannot be requested directly because it calls the "RenderBody()" method" and the same for RenderSection(). Can anyone help me ?
Thanks, Eduard
Hey Eduard
Did you read my answer to OP?
If there's something I need explaining again please ask (I know I might not have explained it very well).
But the way around this problem is basically to either remove the "RenderBody()" or call the template that inherits from the layout you're trying to call - since you cannot call that page directly.
Hi Maciej,
Is your doc type using the master template to render your page?
is working on a reply...