Tuesday, August 16, 2011

Does anyone know how to replace this HTML markup with Razor syntax?

Does anyone know how to emulate this behavior with Razor syntax? I need the blank field, but what is more, I need the blank field to stay around as an option once a match is made.

<select id="Foo" name="Foo">

   <option value="">

   @foreach (var item in FooGetter.GetAll())

   {

      if (FooOfTheMoment == item.Id)

      {

         <option value="@item.Id" selected>@item.Name</option>

      } else {

         <option value="@item.Id">@item.Name</option>

      }

   }

</select>

No comments:

Post a Comment