Im following Paul Seals videos on taking a static bootstrap site and converting it to an Umbraco CMS site. The tutorial is being done on v7 but I have v8 installed.
It's all going fine, but I can't figure out how to get the current page in a partial view.
TemplatePage is not available in v8 as far as I'm aware, it has to be ViewPage.
Interestingly, if I put a breakpoint on that line it appears that Model is null.
Yeah making my way through the series just now...
I had actually tried that and couldn't get it to work which is why I went with what I did, probably something in my set-up.
cheers
I suppose it depends if you are passing in a model or not from the view. If you are not passing in a specific model, then it will pass in the IPublishedContent for you automatically, meaning we can use my example above.
Have a look at my v8 starter kit to see how I've done it on there.
umbraco 8 - get current page from partial view
Im following Paul Seals videos on taking a static bootstrap site and converting it to an Umbraco CMS site. The tutorial is being done on v7 but I have v8 installed.
It's all going fine, but I can't figure out how to get the current page in a partial view.
The tutorial uses
intro being a document type of text box input which I added to my home page under compositions.
Under content I can now enter text into my new control, but Im not sure how to insert this into the
<h2>
tag as above.If needed here is the video, the relevant part is at 10:56 https://www.youtube.com/watch?v=zRDHKisHCQ&list=PL90LHquhD--OWQNLyO1-KRxVDd0NPBfZ&index=5
I have tried using
but get a null reference exception.
thanks
Hello Damion,
If you want to use current pages properties in partial view then simply write as below.
Hope this will work,
Ronak.
Hi
thanks for your reply but Model does not seem to contain a definition for Content, any ideas?
thanks
Change That @inherits UmbracoViewPage to
@inherits Umbraco.Web.Mvc.UmbracoTemplatePage in partial view.
TemplatePage is not available in v8 as far as I'm aware, it has to be ViewPage. Interestingly, if I put a breakpoint on that line it appears that Model is null.
try something like that Where Items is the model and you have to pass it.
Have you tried changing:
to
I've very similar code on my site, and the only difference seems to be this, as far as I can tell.
Hi
Had tried that, althought the Umbraco.Web.Mvc. part of the name is unnecessary, either way the model is still null.
Hey,
> Umbraco.Web.Mvc. part of the name is unnecessary
Today I learned!
Could you post some more of your code from both your partial and where you use it?
The code you have in your original post shouldn't be the problem at least.
In my experience the null reference exception can get thrown in instances where you use @ in front of code, already inside of a code section like
Hope this helps, or someone more experienced can enlighten us :D
Hi all,
the answer to this for v8 is
@Umbraco.AssignedContentItem.GetProperty("intro").GetValue()
Hi Damion
I'm glad to hear you're watching my videos :^)
The right way to do it in v8, without ModelsBuilder, is like this:
Hi Paul,
Yeah making my way through the series just now... I had actually tried that and couldn't get it to work which is why I went with what I did, probably something in my set-up. cheers
I suppose it depends if you are passing in a model or not from the view. If you are not passing in a specific model, then it will pass in the IPublishedContent for you automatically, meaning we can use my example above.
Have a look at my v8 starter kit to see how I've done it on there.
https://github.com/prjseal/CodeShare-Umbraco-Starter-Kit-for-v8
Here is a partial example:
https://github.com/prjseal/CodeShare-Umbraco-Starter-Kit-for-v8/blob/master/src/CSUSK.Web/Views/Partials/Content/_ArticleContent.cshtml
It gets called from this view
https://github.com/prjseal/CodeShare-Umbraco-Starter-Kit-for-v8/blob/master/src/CSUSK.Web/Views/Article.cshtml
When not passing a model and using your code above I get
"Cannot convert method group 'Value' to non-delegate type 'object'" but I don't see why I'd get that.
I'll have a look at those links later then,
cheers again
is working on a reply...