2

I know I can conditionally add an id value via

<select id="@(aBool ? @someId: "")"

I don't want id="". This won't pass W3C validation and appears to make jQuery slam its face into the ground. Can I go a step further and conditionally add id?

Something like this (doesn't work):

<select @(aBool ? id=\"@someId\": "")

P.Brian.Mackey
  • 41,438
  • 63
  • 228
  • 337

1 Answers1

5

It's just text, so using @(cond? "id='meep'" : "") should do it.

As a side note, I finally figured out how you embed expressions in Razor!

Blindy
  • 60,429
  • 9
  • 84
  • 123
  • +1 Sure enough, its not as magical as I thought. `@(cond? "id='" + @meep + "'" : "")` is what I am looking for. – P.Brian.Mackey Aug 30 '11 at 15:38
  • You don't even need the second `@` in that expression since you're already in an expression. It just reverts back to the C# meaning which does nothing in this case. – Blindy Aug 30 '11 at 15:41