DmitryEfimenko / TwitterBootstrapMvc

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

How to prepend LabelText with some text #425

Open wlodarzmar opened 8 years ago

wlodarzmar commented 8 years ago

I have:

Html.Bootstrap().FormGroup().TextBoxFor(model => model.SomeProperty).Label()

SomeProperty has DisplayAttribute. I need to prepend Display.Name text with some other text. How can I write custom method (extension method?) to have sth like this:

Html.Bootstrap().FormGroup().TextBoxFor(model => model.SomeProperty).Label().PrependText("some text")

Thanks in advance.

DmitryEfimenko commented 8 years ago

there is a .Prepend("") method on the textbox. Will it work for you?

Html.Bootstrap().FormGroup().TextBoxFor(model => model.SomeProperty).Prepend("some text")

Perhaps I miunderstand the question. If that's the case, please provide a bit more details using an example. What's the value of DisplayAttribute, and what's the exact desired outcome.

wlodarzmar commented 8 years ago

.Prepend("") method on the textbox works ok for me.

image

but it would be better to add some text before label text. I have property in view model:

[Display(Name = "Some property text")]
        public decimal SomeProperty { get; set; }

and I need to prepend only label text with some number like this: image

DmitryEfimenko commented 8 years ago

I don't think customizing BMVC to allow this would be the best solution. It seems like a very custom use case. However, it's not hard to achieve. Check out this question/answer on stackoverflow. Basically you can create an extension method to get the value of [Display] attribute for a given property and then you can just used that exteionsion method in BMVC's .Label() method.

wlodarzmar commented 8 years ago

thank you for help.