TwitterBootstrapMvc icon indicating copy to clipboard operation
TwitterBootstrapMvc copied to clipboard

How to prepend LabelText with some text

Open wlodarzmar opened this issue 8 years ago • 4 comments

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.

wlodarzmar avatar Jun 10 '16 13:06 wlodarzmar

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.

DmitryEfimenko avatar Jun 10 '16 16:06 DmitryEfimenko

.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

wlodarzmar avatar Jun 11 '16 06:06 wlodarzmar

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.

DmitryEfimenko avatar Jun 11 '16 18:06 DmitryEfimenko

thank you for help.

wlodarzmar avatar Jun 14 '16 06:06 wlodarzmar