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
  • 43,228
  • 68
  • 238
  • 348

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
  • 65,249
  • 10
  • 91
  • 131
  • +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