I'm creating a template for blog posts and within the master template I have a part for @RenderBody() in the Blog Template, which has a child template called BlogPost. When I try to load the blog page which has the @RenderBody() in it, I get the following error:
The file "~/Views/Blog.cshtml" cannot be requested directly because it calls the "RenderBody" method.
However when I run the blog article from url it loads perfectly and renders the page.
Why is this and how can I render my blog page without getting this error?
I believe I are trying to render a page the uses the Master template as it's template. You cannot directly use templates in your pages that call @RenderBody.
Try setting your blog page to use the child template that has the Master template as it's parent. You can use
Unable to reuse @RenderBody()
I'm creating a template for blog posts and within the master template I have a part for @RenderBody() in the Blog Template, which has a child template called BlogPost. When I try to load the blog page which has the @RenderBody() in it, I get the following error:
However when I run the blog article from url it loads perfectly and renders the page.
Why is this and how can I render my blog page without getting this error?
Hi Jonathan,
I believe I are trying to render a page the uses the Master template as it's template. You cannot directly use templates in your pages that call @RenderBody.
Try setting your blog page to use the child template that has the Master template as it's parent. You can use
in your child template for that.
Hope I could be of some help.
Hi Filipe Sousa,
Thank you, it took me about 10-20 minutes after posting this to realise what I was doing wrong so now I have my master template structure like this:
Thanks for your help!
Jonathan
is working on a reply...