daveaglick / FluentBootstrap

Provides extensions, helper classes, model binding, and other goodies to help you use the Bootstrap CSS framework from .NET code.
http://www.fluentbootstrap.com
MIT License
200 stars 76 forks source link

Passing Html string into Text now renders as text #55

Closed Ready4Next closed 8 years ago

Ready4Next commented 8 years ago

Hi,

When making a @Html.Bootstrap().Button("<span class=\"fa fa-3x fa-clock-o\"></span>", ButtonType.Button)

Now renders as `

` It used to work in earlier versions... Is there any good reason to have changed that ? Thanks :)
daveaglick commented 8 years ago

It was changed via #53 due to concerns over security. Specifically, FluentBootstrap was using different escaping rules than Razor does with the @ syntax. I agreed with the PR that it makes sense to escape by default, and then allow the developer to opt-out of escaping (rather than the other way around).

Just put your raw HTML inside a new HtmlString and you should be good to go:

@Html.Bootstrap().Button(new HtmlString("<span class=\"fa fa-3x fa-clock-o\"></span>"), ButtonType.Button)
Ready4Next commented 8 years ago

Thanks for the complete answer Dave,

I already have tried that solution, but I get an error saying

Cannot convert from 'System.Web.HtmlString' to 'string'

There is no overload for Button to take a IHtmlString instead of a string. So even Html.Raw() does not work. Do you plan to add one or maybe there is another solution ?

Ready4Next commented 8 years ago

I have just checked #53, and I see that AddContent serve precisely what I intented to do, so instead of

@Html.Bootstrap().Button(new HtmlString("<span class=\"fa fa-3x fa-clock-o\"></span>"), ButtonType.Button)

I have done that this way:

Html.Bootstrap().Button("", ButtonType.Button).AddContent(Html.Raw("<span class=\"fa fa-3x fa-clock-o"))

And it does the trick :), maybe adding an overload in the future would be clearer :)

Thanks for this great lib :)

daveaglick commented 8 years ago

Perfect! Glad you got it worked out.