DmitryEfimenko / TwitterBootstrapMvc

Fluent implementation of ASP.NET-MVC HTML helpers for Twitter Bootstrap.
Apache License 2.0
224 stars 79 forks source link

using html text in ActionLinkButton #159

Closed gicalle closed 10 years ago

gicalle commented 10 years ago

hello Dmitry, i'm using BMVC V2 for Bootstrap 2.3.2

@Html.Bootstrap().ActionLinkButton("TEST", "index").Size(ButtonSize.Small).RouteValues(new { post = Model }).Style(ButtonStyle.Warning)

generates correctly

<a class="btn btn-small btn-warning" href="/Pass?post=5">TEST</a>

but how can i generate this, so that a 'badge' is displayed in the button itself?

<a class="btn btn-small btn-warning" href="/Pass?post=5">TEST <span class="badge badge-info">
    5</span></a>

i've tried

@Html.Bootstrap().ActionLinkButton("TEST <span class='badge badge-info'>5</span>", "index").Size(ButtonSize.Small).RouteValues(new { post = Model }).Style(ButtonStyle.Warning)

but the text is always converted to html encoded text, thus resulting in this button:

<a class="btn btn-small btn-warning" href="/Pass?post=5">TEST &lt;span class='badge badge-info'&gt;5&lt;/span&gt;</a>

or maybe there is an alternative way to use actionlinks together with badges / custom html?

DmitryEfimenko commented 10 years ago

there is another extension method on ActionLinkButton: .LinkTextAsHtml(). Using it will make sure your html does not get encoded. maybe I should make this behavior default...

gicalle commented 10 years ago

Ok thanks, that will do the trick. I hadn't updated to the latest version, so was unable to find it myself...

Maybe it's a good idea to make it default, because it doesn't interfere with 'plain text'. Everything will work and you're able to put in html from time to time.

gicalle commented 10 years ago

hm,

@Html.Bootstrap().ActionLinkButton("please <b'>click</b>", "TEST").LinkTextAsHtml(true)

is generating

<a class="btn  btn-default" href="Pass/TEST">please &lt;b&gt;click&lt;/b&gt;</a>

instead of

<a class="btn  btn-default" href="/Pass/TEST">please <b>click</b></a>
DmitryEfimenko commented 10 years ago

Hold on. I was originally fixing this issue for ActionLink. Must have forgot to apply the same for the ActionLinkButton

DmitryEfimenko commented 10 years ago

this is fixed. Please get latest. Also deprecated LinkTextAsHtml method. Now this behavior is default.