TwitterBootstrapMvc
TwitterBootstrapMvc copied to clipboard
How to prepend LabelText with some text
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.
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.
.Prepend("") method on the textbox works ok for me.
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:
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.
thank you for help.