Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
Hi,
I call a view from a template and pass an 'item' obejct to it:
@Html.Partial("myView"), item)
It works fine and I can call properties in my 'item' object in the view with
@Model.Value("propName")
But how can I get the Model of the page (node) that the view is called from? Model no longer refers to the page that the website visitor is viewing.
Hi Martin
If you make your partial view have an inherits statement at the top eg:
@inherits UmbracoViewPage<YourCustomModel>
(instead of any normal MVC @model declaration you might have)
Then you can access the current page model via:
Umbraco.AssignedContentItem
eg @Umbraco.AssignedContentItem.Name
@Umbraco.AssignedContentItem.Name
regards
Marc
Thanks, Marc! That was just my need! :)
Had
@inherits Umbraco.Web.Mvc.UmbracoViewPage<IPublishedElement>
Changed it to:
@inherits UmbracoViewPage<IPublishedElement>
And now I can call for instance:
Umbraco.AssignedContentItem.Children().Where(x => x.IsVisible());
is working on a reply...
Write your reply to:
Upload image
Image will be uploaded when post is submitted
How to get the "original" Model when in partial view with it "own" Model?
Hi,
I call a view from a template and pass an 'item' obejct to it:
It works fine and I can call properties in my 'item' object in the view with
But how can I get the Model of the page (node) that the view is called from? Model no longer refers to the page that the website visitor is viewing.
Hi Martin
If you make your partial view have an inherits statement at the top eg:
(instead of any normal MVC @model declaration you might have)
Then you can access the current page model via:
eg
@Umbraco.AssignedContentItem.Name
regards
Marc
Thanks, Marc! That was just my need! :)
Had
Changed it to:
And now I can call for instance:
is working on a reply...