title: How to concisely create optional HTML attributes with razor view engine?
body: <p>I'm looking for a way to write the following code with less lines of code (maybe 5).  I suppose I could do the same thing as the selected class but this razor syntax isn't looking pretty.</p>
  
  <pre><code>&lt;ul&gt;
  @foreach (var mi in Model.MenuItems) {
    &lt;li@(mi.Selected?" class=\"selected\"":null)&gt;
    @if (string.IsNullOrEmpty(mi.Title)) {
      &lt;a href="@mi.Href"&gt;@mi.Text&lt;/a&gt;
    } else {
      &lt;a href="@mi.Href" title="@mi.Title"&gt;@mi.Text&lt;/a&gt;
    }
    &lt;/li&gt;
  }
  &lt;/ul&gt;
  </code></pre>