title: Browsers act different on anchor with image on MVC3 Razor
body: <p>world! I have a odd thing with an "a" tag. The big idea is rendering something like this: <code>&lt;a href="/*Retrieve an original sized image from database*/"&gt;&lt;img src="/*Retrieve an original sized image and resize to thumbnail*/"/&gt; &lt;/a&gt;</code>.</p>
  
  <p>This is what I need to implement some jQuery zooming image plugins. I have 2 methods - one simply gets image form DB, another makes a thumbnail.</p>
  
  <p>The problem is different browser behavior to my actions: FF, Chrome, Opera shows an original image in another window (as expected). Safari offers to download a jpg file called "GetImageThumbnail" and IE offers to download unknown file called GetImageThumbnail (opens as jpeg image).</p>
  
  <p>Here is anchor href text:  <code>"/Image/GetFullSizedImage?goodId=20"</code> - same on all browsers.</p>
  
  <p>This is helper in View: <code>
          @Html.GetImageLinkWithInnerImage(Model.Id)</code>.</p>
  
  <p>Here is a helper implementation(might be useful for folks who want to make anchors and images in helper methods:)</p>
  
  <pre><code> public static MvcHtmlString GetImageLinkWithInnerImage(this HtmlHelper helper, int goodid)
     {
         var controller = helper.ViewContext.Controller as Controller;
         if (controller != null)
         {
             var urlHelper = controller.Url;
             var photoUrl = urlHelper.Action("GetFullSizedImage", "Image", new { goodId = goodid });
             var anchorBuilder = new TagBuilder("a");
             anchorBuilder.MergeAttribute("href", photoUrl + " ");
             var innerPhotoUrl = urlHelper.Action("GetImageThumbnail", "Image", new { goodId = goodid });
             var imgBuilder = new TagBuilder("img");
             imgBuilder.MergeAttribute("src", innerPhotoUrl);
             imgBuilder.MergeAttribute("alt", "Фото товара");
             anchorBuilder.InnerHtml = imgBuilder.ToString(TagRenderMode.SelfClosing);
             return MvcHtmlString.Create(anchorBuilder.ToString());
         }
         return null;
     }
  </code></pre>
  
  <p>And method retrieves image from DB:</p>
  
  <pre><code> public FileContentResult GetFullSizedImage(int goodId)
      {
          byte[] imageData = _db.GetGood(goodId).Image;
  
          if (imageData != null)
          {
              int imageWidth;
              int imageHeight;
              var imageFile = GetImageFromBytes(imageData, out imageWidth, out imageHeight);
  
              return ImageReadyFileContentResult(imageWidth, imageFile, imageHeight);
          }
  
          return NoPhotoFileContentResult();
      }
  </code></pre>
  
  <p>This is an HTML output:</p>
  
  <pre><code>&lt;a href="/Image/GetFullSizedImage?goodId=20 "&gt;&lt;img alt="Фото товара" src="/Image/GetImageThumbnail?goodId=20" /&gt;&lt;/a&gt;
  </code></pre>
  
  <p>What am I doing wrong?</p>