What happens if you do @Html.DisplayFor(m => m.Title)? If you get the same problem then for some reason the display template for strings is resolved to a view that has StartPage as model.
Either way, unless you have a custom display template for strings your Title property will have different rendering in view and edit mode may not be what you want. Instead you can do something like <p @Html.EditAttributes(x => x.Title)>@Model.Title</p>
DisplayFor didn't work either. The EditAttributes did work. Interresting as I never would have thought to use that. Why is or how is that working?
As Joel wrote, DisplayFor (and PropertyFor becouse PropertyFor only is a wrapper for DisplayFor to support on page edit) will look for a display template named string which takes string as the model. It seems to me that you have a string partial view that takes the pagetype as model under view->shared->displaytemplates.
Corbin, EditAttributes returns a string with HTML attributes which marks the element they are added to as the container for a property. I've found that I rarely use PropertyFor and instead use EditAttributes as PropertyFor is more intrusive when rendering properties in (DOPE) edit mode as it wraps them in a element which isn't rendered in view mode.
I guess I would have thought ES7 would have handled string properties inherently. I didn't set up any template or partial view. Joel, interesting that you go with the EditAttributes when PropertyFor is used in the default templates (granted the default Page Type property is an XhtmlString). I have a lot of places I'm going to use this. Thanks for the help.
what's your EPiserver version installed? are you using the preview version?
Corbin, this is a really, really far fetched and wild guess, but could it be that you only experience this when Title is null, or vice versa, only when it's not null?
I have Page Type called StartPage.
public class StartPage: PageData
[Editable(true)]
[Display(
Name = "Title",
Description = "The page's title",
GroupName = SystemTabNames.Content,
Order = 1)]
public virtual String Title { get; set; }
[Display(Name = "Content Area",
Description = "A block goes here",
GroupName = SystemTabNames.Content,
Order = 2)]
public virtual ContentArea ContentArea { get; set; }
}
Layout:
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>@ViewBag.Title</title>
</head>
<body>
<h2>My Site</h2>
<div>
@RenderBody()
</div>
</body>
</html>
Here is my Start View
@using EPiServer.Core
@using EPiServer.Web.Mvc.Html
@model Site.Models.Pages.StartPage
@{
Layout = "~/Views/_Layout.cshtml";
}
<div>
@Html.PropertyFor(m => m.Title)
</div>
<div>
@Html.PropertyFor(m => m.ContentArea)
</div>
When I go to edit my page, I get this: