SaaS CMS has officially launched! Learn more now.

Page Type Property Problem


I have Page Type called StartPage.

public class StartPage: PageData

             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; }



<!DOCTYPE html>

    <meta name="viewport" content="width=device-width" />
    <h2>My Site</h2>

Here is my Start View

@using EPiServer.Core
@using EPiServer.Web.Mvc.Html

@model Site.Models.Pages.StartPage

        Layout = "~/Views/_Layout.cshtml";

@Html.PropertyFor(m => m.Title)
@Html.PropertyFor(m => m.ContentArea)

When I go to edit my page, I get this:

The model item passed into the dictionary is of type 'System.String', but this dictionary requires a model item of type 'Site.Models.Pages.StartPage'

And the YSOD is highlighting the @Html.PropertyFor(m => m.Title). If I change it to use @Model.Title instead, I can't edit on page, but it doesn't error out.
This doesn't happen if I have the Title property typed as an XhtmlString. The ContentArea renders fine and lets me drop a block onto it.
Any ideas?

Dec 13, 2012 22:58

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>

Edited, Dec 14, 2012 0:16

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?

Dec 17, 2012 19:29

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.

Dec 18, 2012 9:05

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.

Dec 18, 2012 9:25

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.

Dec 18, 2012 17:23

what's your EPiserver version installed? are you using the preview version?

Dec 20, 2012 13:07

I'm using the release version of 7.

Dec 21, 2012 22:25

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? 

Edited, Dec 21, 2012 23:24
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.