From where are you calling this code? If it's just for a partial you could directly render the partial from your other views, which will result in the model automatically being passed on.
When you render a view as shown above, you can pass the model as a second parameter:
public ActionResult ViewAccount()
{
return View("~/Views/MemberAccount.cshtml", viewModel);
}
The view this is on inherits from UmbracoViewPage<IPublishedContent>, which I assumed (maybe wrongly) would make the content available as the model, is that not the case?
Interestingly, every partial opened from the homepage has access to all the content, it's only when I'm opening an entirely different view that I see this.
Right, turn out I copied the wrong line into the post and there is some functionality to retrieve member data in the partial. The full sequence is
An href to "@Url.Action("ViewAccount", "MemberAccount")"
which does this
return View("~/Views/MemberAccount.cshtml");
within that page, @inherits Umbraco.Web.Mvc.UmbracoViewPage<IPublishedContent> and 3 partials are rendered (one of which mentioned above has some functionality), but it's at this point that IPublishedContent is null.
All 3 partials use dictionary items, and all are missing.
IPublishedContent is null in my View
When opening a View from a controller like this
And the View inherits like this
I'm finding that IPublishedContent in the View is null, therefore I cannot get Dictionary Items.
IPublishedContent is not null in the main View where this one is opened from.
Am I missing something here?
Hi Damion :-),
From where are you calling this code? If it's just for a partial you could directly render the partial from your other views, which will result in the model automatically being passed on.
When you render a view as shown above, you can pass the model as a second parameter:
Hi,
I'm calling it from
The view this is on inherits from
UmbracoViewPage<IPublishedContent>
, which I assumed (maybe wrongly) would make the content available as the model, is that not the case?Interestingly, every partial opened from the homepage has access to all the content, it's only when I'm opening an entirely different view that I see this.
Hi,
I'm wondering why it's working on the Homepage, as the code you provided sets the Model explicitly to
null
in the Controller it inherits from.Can you try rendering the View directly as a partial instead of using the Action? As you don't have any functionality in the controller for now.
P.S. instead of wrapping the
Html.RenderAction
in@{...}
you can also useHtml.Action
directly from the html.Ok, what you've said has given me a thought.... Going to try something and I'll let you know how it goes after lunch (important stuff first!)
Right, turn out I copied the wrong line into the post and there is some functionality to retrieve member data in the partial. The full sequence is
An href to
"@Url.Action("ViewAccount", "MemberAccount")"
which does this
return View("~/Views/MemberAccount.cshtml");
within that page,
@inherits Umbraco.Web.Mvc.UmbracoViewPage<IPublishedContent>
and 3 partials are rendered (one of which mentioned above has some functionality), but it's at this point that IPublishedContent is null.All 3 partials use dictionary items, and all are missing.
Think I'll bin it and try it from scratch
is working on a reply...