title: ASP.NET MVC 3.0 Conditionally writing inline text within a tag
body: <p>I have this tag in my menu</p>
  
  <pre><code>&lt;li&gt;&lt;a href="/"&gt;Home&lt;/a&gt;&lt;/li&gt;
  </code></pre>
  
  <p>and I was wanting to insert a <strong>class="selected"</strong> if the current controller was the HomeController.  So I modified the tag to look like this.</p>
  
  <pre><code>&lt;li&gt;&lt;a href="/" @if (ViewContext.Controller.ToString().EndsWith("HomeController")) { Response.Write("class=\"selected\""); }&gt;Home&lt;/a&gt;&lt;/li&gt;
  </code></pre>
  
  <p>Now, I see the <strong>class=<code>&amp;quot;</code>selected<code>&amp;quot;</code></strong> appear at the top of the page and the rest of the markup is messed up.  I just wanted to have the tag look like this </p>
  
  <pre><code>&lt;li&gt;&lt;a href="/" class="selected"&gt;Home&lt;/a&gt;&lt;/li&gt;
  </code></pre>
  
  <p>If the current controller is the HomeController.</p>
  
  <p>Any ideas what I did wrong?</p>
  
  <p>Thanks!</p>