RenderLink and custom attribute, space is converted to plus-sign

972 views Asked by At

Using Glass mapper Im trying to create an editable link property doing the following using razor and MVC:

@(RenderLink(
  x => x.Settings.First().CompanyLink,
  new { @class="navbar-brand page-scroll" },
  true
)))

However.. for some reason the two css-classes gets concated with a plus sign between them.. so the end result of the class-attributes value is "navbar-brand+page-scroll".. Just as an ugly work-around I was hoping that:

@(RenderLink(
  x => x.Settings.First().CompanyLink,
  new { @class="navbar-brand page-scroll" },
  true
).ToHtmlString().Replace("+", " ")))

Would solve it.. and it kind of did.. but as soon as you edit the link and the page updates, the classes gets concated again.

Any ideas?

2

There are 2 answers

6
Michael Edwards On

this looks like it might be a bug. I will investigate and get back to you.

Mike

0
Komainu85 On

I have written a helper class for Razor / Glass so you can add HTML elements. It could work as a different option for adding your css classes.

See blog here: http://mikerobbins.co.uk/2015/07/29/sitecore-razor-glass-attribute-helper-methods-fluent-api/

You can use the helper like this:

@(RenderLink(x => x.Settings.First().CompanyLink,new HtmlAttributes().CssClass("navbar-brand page-scroll").Render())