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?
Try this one:
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?
Try output just property value: @CurrentPage["PageName"]. Does it renders some content? What data type is for the property that is not rendering?
@CurrentPage["PageName"] gives me raw html like
I am wondering why the .Display would return nothing.
Hi it may be worth taking a look at the following thread as it contains a similar subject: