title: Trying to alternate css code based on condition in URL path
body: <p>I am trying to alternate a <code>CSS</code> class in a <code>&lt;fieldset&gt;</code>. Normally a <code>@helper</code> function would work fine (see the <code>@helper</code> below), however I have two (2) circumstances that won't allow it to work properly.</p>
  
  <p>First, I am using a <code>Input.Edit.cshtml</code> field template in <code>~/Views/EditorTemplates/Fields</code>.</p>
  
  <p>This basically means that as I build up a form, the <code>Input.Edit.cshtml</code> file is being called each time for as many <code>&lt;input&gt;</code>'s as I have in my form.</p>
  
  <p>Second, I am using a condition to check the path of the URL in order to only apply this <code>CSS</code> alternating class on pages below a certain path. Specifically, I want to apply this change to pages under my <code>~/Services</code> path. On all other pages I do not want the change applied. I check this condition using <code>Request.Url.AbsoluteUri</code> as you see below.</p>
  
  <p>This is where I think my problem lies, as the alternating code is applied but then because it is called again for the same condition on the same page it is applied incorrectly due to my logic.</p>
  
  <p>Now it could be that I am just stuck with the problem.</p>
  
  <p>Here is the code:</p>
  
  <pre><code>@{
      string CurrentUrl = Request.Url.AbsoluteUri;
  }
  
  @helper ResponsiveCss(string cssClass)
  {
      if (ViewBag.count == null) { ViewBag.count = 0; }
      &lt;text&gt;class="@(ViewBag.count % 2 == 1 ? cssClass : "one-half last")"&lt;/text&gt;
      ViewBag.count++;
  }
  
  @if (CurrentUrl.Contains("Services"))
  { 
      &lt;fieldset @ResponsiveCss("one-half")&gt;
  
          //Label and Input code
  
      &lt;/fieldset&gt;
  }
  </code></pre>
  
  <p>What should happen is that the <code>class="one-half"</code> is applied on the first <code>&lt;fieldset&gt;</code> that is created in the form, and then <code>class="one-half last"</code> on the second that is created.</p>
  
  <p>Instead what is happening is that <code>class="one-half"</code> is <strong>NOT</strong> being applied on the first <code>&lt;fieldset&gt;</code> that is created, but rather <strong>ALL</strong> <code>&lt;fieldset&gt;</code>'s are being created with <code>class="one-half last"</code>.</p>
  
  <p>Sorry if that is not clear. Any thoughts on if I can make this work given the circumstances  (and how)?  Thanks.</p>