1

I am able to write in my MVC 3 view:

@Html.TextBoxFor(model => model.Something, new { style = "display: none;" })

But how can I do the same with a LabelFor?

To explain why: I am hiding the label initially but using JQuery to show this label at a later point. I guess I can use JQuery to initially hide it as well, but I would rather do it this way is possible.

Eranga
  • 32,181
  • 5
  • 97
  • 96
Stian
  • 1,261
  • 2
  • 19
  • 38

2 Answers2

4

Have a look at this post How to specify ID for an Html.LabelFor<> (MVC Razor)

Community
  • 1
  • 1
Per Kastman
  • 4,466
  • 24
  • 21
  • 1
    Thanks. I think that your suggestion about just wrapping it in a hidden element (before your edit) should be enough for now, but the knowledge for how to specify ID for labelfor is great for later use. – Stian Jan 10 '12 at 09:32
1

Personally I'd suggest you wrap the TextBox and Label in a containing div, set that element to display:none and have JQuery show/hide the containing div rather than the individual elements.

Amalea
  • 526
  • 1
  • 6
  • 17