November Happy Hour will be moved to Thursday December 5th.

Html.PropertyFor question

Vote:
 

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?

#74930
Sep 11, 2013 16:06
Vote:
 

Try this one:

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

    

#74942
Sep 11, 2013 23:29
Vote:
 

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?

Paul

#86724
May 29, 2014 4:22
Vote:
 

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

#86759
May 29, 2014 21:04
Vote:
 

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

 

I am wondering why the .Display would return nothing. 

#88733
Jul 28, 2014 17:36
Vote:
 

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

http://world.episerver.com/Modules/Forum/Pages/Thread.aspx?id=87488

#88741
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.