Try our conversational search powered by Generative AI!

Html.PropertyFor question


In MVC to be able to get a EPiServer property and make it editable in the on-page-edit I normally use @Html.PropertyFor(m => m.CurrentPage.PageName). But in some cases, eg on the _Root.cshtml I am not sure if a specific property exists, therefor I want to use the code below:

@if (Model.CurrentPage["PageName"] != null) 
   @Html.PropertyFor(m => m.CurrentPage["PageName"]) 

But when I run this I got this exception:

Unsupported expression. The body of the expression must either be a MemberExpression or a UnaryExpression. On the PropertyFor-row.

Isn't this possible? I am new to MVC so maybe I am doing it totally wrong?

Sep 11, 2013 16:06

Try this one:

<div @Html.EditAttributes("PageName")>@Html.Display("PageName")</div>


Sep 11, 2013 23:29

Hi Valdis,

I have tried this and Html.EditAttributes is getting the on-page edit working perfectly, however Html.Display is always rendering nothing. Any idea why?


May 29, 2014 4:22

Try output just property value: @CurrentPage["PageName"]. Does it renders some content? What data type is for the property that is not rendering?

May 29, 2014 21:04

@CurrentPage["PageName"] gives me raw html like 


I am wondering why the .Display would return nothing. 

Jul 28, 2014 17:36

Hi it may be worth taking a look at the following thread as it contains a similar subject:

Jul 28, 2014 23:16
This thread is locked and should be used for reference only. Please use the Episerver CMS 7 and earlier versions forum to open new discussions.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.