title: Looping through query string using Razor
body: <p>I have the following C# Razor in my View:</p>
  
  <pre><code>@{var activeFilters = 0;}
  @foreach (string key in Request.QueryString)
  {
      string value = Request.QueryString[key];
  
      if (!String.IsNullOrEmpty(value))
      {
          if (key.ToLower() != "filter" || key.ToLower() != "page" || key.ToLower() != "gridtype")
          {
              activeFilters++;
          }
      }
  }
  </code></pre>
  
  <p>This loops through the query string and counts have many have valid values to populate the activeFilters var. It also ignores filter, page and gridtype.</p>
  
  <p>Here are some examples:</p>
  
  <pre><code>?page=1 (0)
  
  ?filter=&amp;other=test (1)
  
  ?filter&amp;other=test (1)
  </code></pre>
  
  <p>The problems I am having:</p>
  
  <ul>
  <li>It doesn't ignore the keys filter, page and gridtype</li>
  <li>It breaks if a query key has no equals e.g. <code>?page</code> with the error <code>Object reference not set to an instance of an object.</code></li>
  </ul>