Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to prepend LabelText with some text #425

Open
wlodarzmar opened this issue Jun 10, 2016 · 4 comments
Open

How to prepend LabelText with some text #425

wlodarzmar opened this issue Jun 10, 2016 · 4 comments

Comments

@wlodarzmar
Copy link

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
Copy link
Owner

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
Copy link
Author

.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
Copy link
Owner

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
Copy link
Author

thank you for help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants