7

I have a very general web page where I display information. I have this code in my .cshtml:

<div style="text-align: left">
    Test&nbsp;&nbsp;<p style="color: #1e83ca;"> @Html.Label(Model.MemberName) &nbsp;&nbsp;&nbsp;&nbsp;</p>
    Beruf&nbsp;&nbsp;@Html.Label(Model.ProfessionName)&nbsp;&nbsp;&nbsp;&nbsp;
    Datum&nbsp;&nbsp;@Html.Label(Model.TestTakenDate.ToString()) 
</div>

I want differentiate the text that I display reading from the database from what is the fixed text. I am using the helper Label and there is no difference. I get all black text. How do I make only what is in the @Html.label in different color? OR what else can I use to make them look different.

6
  • I tried to do it with <p> tag but that writes on the next line so I dont want that. All the info has to be on one line. Commented Jun 19, 2012 at 14:37
  • Look at html attributes, that is right place to define them. Also it is recommended to put html attribute classes in a css document. Commented Jun 19, 2012 at 17:14
  • I don't want it for the whole <div> section but only for the text specifies in the label. What attribute can I use for the @html.Label ?? Commented Jun 20, 2012 at 8:27
  • 2
    Use <span> for the rest of the text. For non-formatted section. Commented Jun 20, 2012 at 9:39
  • 1
    I used span and it works fine. Thanks. Commented Jun 20, 2012 at 9:50

5 Answers 5

6

I just did the following and it worked for me:

@Html.Label("This is a label", new { style = "color:#ff0000"})
Sign up to request clarification or add additional context in comments.

Comments

4

As mentioned in my comments, try to use <span>. That will work !

Comments

2
@Html.Label(Model.ProfessionName, new {@class = "mylabel" })

in css

.mylabel
{
   color: green;
}

1 Comment

It doesn't take in the second parameter as you suggested.How do I specify my style to it?
0

Try giving your @Html.Label classes.

so in your css :

.database { color: #1e83ca; }

and in your cshtml

@Html.Label(Model.MemberName, new { @class = "database"} )

1 Comment

I tried this but it is not taking in the second parameter as class.
0

Can you specify the HTML attributes by supplying an additional parameter to the Label HTMLHelper?

Something like:

<%= Html.Label("This is a label", new { style : "color:#FF0000;" } ) %>

1 Comment

It is not taking in second parameter as style. What else?

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.