Umbracoarmus! Casting your current page object

Imagine this, You have a IPublished content object that you’re using in your view. It is set up like this

var currentPage = Umbraco.CurrentPage();

You can access your property values like so

@currentPage.MyProperty

But when you call any other methods on myProperty such as .HasValue you get an exception as the value throws an exception. Annoying right.
You just need to cast the property as follows

((Umbraco.Web.Models.DynamicPublishedContent)CurrentPage).GetProperty(“MyProperty”).HasValue

Then you can gain access to the property.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s