CssClass attribute not working with Html.PropertyFor

Vote:
 

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.

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

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

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

    

#80390
Jan 22, 2014 11:26
Vote:
 

This is still not working for me :-(

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

or

@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)

#89897
Edited, Aug 28, 2014 11:51
Vote:
 

See this blog post:

http://tedgustaf.com/blog/2014/4/render-image-properties-in-episerver-75/

#89916
Aug 28, 2014 12:04
Vote:
 

The attributes you can use with html.propertyfor is explained by joel. http://joelabrahamsson.com/episerver-7-and-mvc-custom-tags-and-css-classes-when-rendering-properties/

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.

#90265
Sep 04, 2014 14:53
Vote:
 

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.

#91492
Oct 07, 2014 15:55
Vote:
 

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 :)

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