title: How to pass uploaded image path to controller via ajax
body: <p>When passing uploaded file through ajax to asp.net MVC controller, file property is showing null value in controller.</p>
  
  <p>image file object taken by <code>document.getElementById('fileUpload').files[0]</code> action and convert to <code>JSON.stringify(fileName)</code> but when pass that object to asp.net mvc controller 
  it is showing null value in mvc controller. </p>
  
  <p>please if any one know how to pass that file to ajax to mvc controller, please post your answer</p>
  
  <p><strong>Admin controller</strong></p>
  
  <pre><code>[HttpPost]
          public string AddRetailer(HttpPostedFileBase file, string storeName, string storeUrl, string ecommercePlatform)
          {
              try {
                  Bswayed.Admin.Retailer retailer = new Bswayed.Admin.Retailer();
                  return JsonConvert.SerializeObject(data);
              } catch (Exception ex) {
                  throw ex;
              }
          }
  </code></pre>
  
  <p><strong>Asp.net upload form</strong></p>
  
  <pre><code> &lt;input type="file" id="fileUpload" name="fileUpload" onchange="this.parentNode.nextSibling.value = this.value"/&gt;Browse
  
  &lt;input class="input-lg"  
  @Html.TextBoxFor(Model =&gt; Model.StoreLogo, new { placeholder=@ViewBag.StoreLogo})
  </code></pre>
  
  <p><strong>Java script(Ajax)</strong></p>
  
  <pre><code> function AddRetailer()
   {    
       try {  
         var storeName = $("#StoreName").val();
         var storeUrl = $("#StoreURL").val();
         var retailerLogoPath = $("#StoreLogo").val();
         var ecommercePlatform = $("#EcommercePlatform").val();
         var fileName = document.getElementById('fileUpload').files[0]
  
         $.ajax({         
             url: $("#addRetailer").val(),
             cache: false,
             type: "POST",         
             data: { 
              file:JSON.stringify(fileName), 
              storeName: storeName, 
              storeUrl: storeUrl, 
              ecommercePlatform: ecommercePlatform 
             },
             dataType: "json",
             success: function (data) {                          
             },
             error: function (resp) {
                 alert(resp);
             }
         });
       }
       catch (e) {
       }
   }
  </code></pre>