title: how to avoid Ampersand(&) being converted to &amp in c# MVC
body: <p>I use MVC model to make the image url and to display it .</p>
  
  <p>I make the image url  like this:</p>
  
  <pre><code>        string baseURL = string.Format("https://abc/Work/LookPage?pbid={0}", model.ID);
  
          var builder = new UriBuilder(baseURL);
          var query = HttpUtility.ParseQueryString(builder.Query);
          query["pg"] = "1";
          query["isStage"] = "false";
          builder.Query = query.ToString();
          model.ImageUrls.Add(1, builder.ToString());
  </code></pre>
  
  <p>and I have a controller named WorkController</p>
  
  <pre><code>    [OutputCache(Duration = 600, VaryByParam = "*", Location = OutputCacheLocation.Client)]
      public virtual ActionResult LookPage(string pbid, int pg, bool? isbody, bool? isStage)
      {
          var ms = this.CreateLookPageImage(pbid, pg, isbody, isStage, false);
  
          if (ms == null)
              return HttpNotFound();
  
          return new FileStreamResult(ms, "image/jpeg");
  
      }
  </code></pre>
  
  <p>and in the view , i write like this:</p>
  
  <pre><code>&lt;a&gt;&lt;img class="shadow" src="&lt;%:Model.ImageUrls[1] %&gt;"/&gt;&lt;/a&gt;
  </code></pre>
  
  <p>This worked actually.
  but sometimes this error comes:</p>
  
  <pre><code>System.NullReferenceException: Object reference not set to an instance of an object.
  </code></pre>
  
  <p>at System.Web.HttpCookieCollection.Add(HttpCookie cookie)
     at CWorks.Web.Filter.SiteSelectorAttribute.OnActionExecuting(ActionExecutingContext filterContext)</p>
  
  <pre><code>[Request.RawUrl]/Work/LookPage?pbid=PBER-2972311310171610590&amp;amp;pg=8&amp;amp;isStage=true
  </code></pre>
  
  <p>because &amp; in the url is being converted to &amp;amp; so the routing doesnot work.
  how can i  avoid the  Ampersand(&amp;) being converted to &amp;amp??</p>
  
  <p>I also donot know why sometimes the url is ok(<code>&amp;</code>) and sometime is not(being converted)</p>