mustang00
mustang00

Reputation: 313

How to I add an element style to text in a viewbag in asp.net MVC?

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.

Upvotes: 2

Views: 10442

Answers (3)

Ajay
Ajay

Reputation: 6590

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)

Upvotes: 3

Radu
Radu

Reputation: 1066

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

Upvotes: 0

maxspan
maxspan

Reputation: 14177

The below code works for me.

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

Upvotes: 1

Related Questions