2

I want to add an element-style to the text and value in a viewbag. How would I go about this?

This is is the code

ViewBag.Title = "Order No:" + " " + Model.OrderID;

and what I want to do is make it bold on the view screen. So it should come out like this for example: Order No: 5.

I normally add styles to the tags to bold the text, but in this case I'm completely clueless on what to do.

6
  • What technology in particular are you talking about? Commented Aug 25, 2015 at 9:02
  • @deceze .Net I think since is using viewBag Commented Aug 25, 2015 at 9:02
  • How about add that tag then? Commented Aug 25, 2015 at 9:03
  • Yeah, in MVC. I did, but its not working. Commented Aug 25, 2015 at 9:05
  • 1
    "MVC" is not particular to Microsoft technologies. If you mean .NET, say .NET. Commented Aug 25, 2015 at 9:06

3 Answers 3

3

try to put your ViewBag.Title in span or label tag and then apply styles on it.

<span style="font-weight:Bold;">ViewBag.Title</span>

Or can directly put it in <b> tag

<b>ViewBag.Title</b>

In c# code:

ViewBag.Error = "Hi, I am <b>bold</b>"

Instead of <b> you can put span or label with style you want. In view:

@Html.Raw(ViewBag.Error)
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, this worked. What if I want to apply it to only that specific text in the viewbag on a specific page? Since this bolds every single viewbag on every page.
1

The below code works for me.

@Html.LabelFor(ViewBag.Title, new {@style = "font-weight:Bold"})

1 Comment

This wasn't able to answer my specific question but this is useful. Thanks!
0

when you display the viewBag title into the page most probably you are using it in a div tag so add a class to it like my boldOrder then in css file you can set the bold property. If you don't know hot to add a bold to a text just check this example

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.