Don't miss out Virtual Happy Hour this Friday (April 26).

Try our conversational search powered by Generative AI!

CssClass attribute not working with Html.PropertyFor


I am trying to render a block with a link list collection and set a custom CSS class on the <ul> element.

@Html.PropertyFor(x => x.LinkListCollection, new { CssClass = "no-bullet"})

This is renders an ul-list with no class set.

<a href="/sv/landningssida/">Landningssida</a>
<a href="/sv/listningssida/">Listningssida</a>
<a href="/sv/Standardsida-1/">Standardsida 1</a>
Why is not the class attribute rendered?
Help is appreciated, thanks.
Jan 22, 2014 10:58

"class" is a protected keyword, you need to use:

@Html.PropertyFor(x => x.LinkListCollection, new { @class = "no-bullet"})


Jan 22, 2014 11:26

This is still not working for me :-(

@Html.PropertyFor(x => x.Image, new { @class = "icon-header-icon" })


@Html.PropertyFor(x => x.Image, new { CssClass = "icon-header-icon" })

Both do not render an image with class 'icon-header-icon'

(Using Episerver 7.5)

Edited, Aug 28, 2014 11:51

See this blog post:

Aug 28, 2014 12:04

The attributes you can use with html.propertyfor is explained by joel.

I sugest you just create a displaytemplate for your property. Either you can use the name of the type or our can use UIHint to render specific templates. If so also make sure you use the PresentationLayer property as well.

[UIHint(UIHint.Image, PresentationLayer.Edit)]

"Passing a custom CSS class only affects those properties for which a HTML element is created when using PropertyFor, such as content areas. In other words, in the below example the CssClass setting won’t actually do anything at all as no element is created when rendering string properties." - Joels blogpost.

Sep 04, 2014 14:53

I have the same problem with images in EPiServer 7.5. When UIHint is set to "Image", EPiServer correctly renders content references using tag. But CSS class is not applied in any way.

@Eric, CSS class should work for images, because they render tag, not only string. So I would expect CSS classes support in default image rendering.

Oct 07, 2014 15:55

Thats is true, I sugest sending in a support issue regarding this. In my case I create a custom displaytemplates most of the time solving the image issue :)

Oct 07, 2014 16:28
* 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.