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

Css Class Not Applying to LinkItemCollection Render

Vote:
 

The following code does not appear to be working correctly.  Any ideas?

@Html.PropertyFor(m => m.Layout.LegalLinks, new { CssClass = "terms", })

Renders the following

I am trying to get the class 'terms' to be applied on the

    element.

    Based on some other posts, I have also tried:

@Html.PropertyFor(m => m.Layout.LegalLinks, new { @class = "terms", })

Any ideas?  Am I missing something blatanly stupid here?

#116545
Feb 02, 2015 5:03
Vote:
 

Hi yes you are missing the fact that the CssClass is not set on the html that is rendered by the DisplayTemplates builtin for linkitemcollection. A lot of these parameters that can be set on the html.propertyfor helper is there for editmode sadly. Have a look at these links written by Joel Abrahamsson.

http://joelabrahamsson.com/episerver-7-and-mvc-custom-tags-and-css-classes-when-rendering-properties/

http://joelabrahamsson.com/how-episervers-html-helper-propertyfor-works/

CustomTag changes the type of element that wrapes the rendered property when rendered in edit mode.

CssClass does not change the CSS class for the wrapping element when rendered in edit mode. EditContainerClass does.

In view mode PropertyFor isn't much more than an alias for DisplayFor. In edit mode it adds a wrapping element to whatever is rendered by DisplayFor. The wrapping element contains attributes that the CMS uses to identify editable properties.

My recommendation is to use your own displaytemplates that you can use with propertyfor. Just create a new LinkItemCollection.cshtml in DisplayTemplates-folder. /Views/Shared/DisplayTemplates/. Then you can change the output just the way you like it.

#116553
Feb 02, 2015 9:12
* 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.