Using Custom Controllers & Models, how to get CurrentPage from UmbracoViewPage?
Hi, I am attempting to use a custom model and controller. I have got so far successfully, but I cant fathom how to get 'Current Page', or its equivilent. I have been following the docs here but must be missing something.
This is a simplified snippet of my old view code that works with the default controller:
@inherits Umbraco.Web.Mvc.UmbracoTemplatePage
if (CurrentPage.HasValue("subtitle"))
{
<span>@CurrentPage.subtitle</span>
}
This is how it now looks:
@using Project.Models;
@inherits Umbraco.Web.Mvc.UmbracoViewPage<myModel>
if (CurrentPage.HasValue("subtitle"))
{
<span>@CurrentPage.subtitle</span>
}
and this is my model (partially based on this blog post):
using Umbraco.Web;
using Umbraco.Web.Models;
namespace Project.Models
{
public class myModel : RenderModel
{
public myModel() : base(UmbracoContext.Current.PublishedContentRequest.PublishedContent) { }
public string variable { get; set; }
}
}
I cannot resolve CurrentPage in my view. I have tried Model.View.CurrentPage and Model.Content.View.CurrentPage but am having no luck. How do I get CurrentPage?
Using Custom Controllers & Models, how to get CurrentPage from UmbracoViewPage?
Hi, I am attempting to use a custom model and controller. I have got so far successfully, but I cant fathom how to get 'Current Page', or its equivilent. I have been following the docs here but must be missing something.
This is a simplified snippet of my old view code that works with the default controller:
This is how it now looks:
and this is my model (partially based on this blog post):
I cannot resolve
CurrentPage
in my view. I have triedModel.View.CurrentPage
andModel.Content.View.CurrentPage
but am having no luck. How do I getCurrentPage
?Hi Paul,
Try to use like this :
Model is your page now.
Thanks,
Alex
We do top quality development.
http://www.ukad-group.com/
Thanks Alex, I have used
Model.Content.GetProperty(...)
. I think I must have found that as you were typing your answer!is working on a reply...