-1

I want to use Ajax.BeginForm which contains a input type="file" multiple. But file value is null if i send it to controller. Because using together JQuery.js and Ajax.js. If I delete Jquery in this View file value not null.

@{
   ViewBag.Title = "Home Page";
}

<script src="~/Scripts/jquery-3.3.1.js"></script>

<script src="~/Scripts/jquery.unobtrusive-ajax.js"></script>

@using (Ajax.BeginForm("Send", "Home",new AjaxOptions { UpdateTargetId="result",HttpMethod="POST",InsertionMode=InsertionMode.Replace},new {enctype="multipart/form-data" }))
{
    <input name="name"  />

    <input   id="files" name="pictures" type="file" multiple />
    <button type="submit"  >SEND</button>

}

<div id="result"></div>

//Controller

 [HttpPost]
    public PartialViewResult Send(string name,IEnumerable<HttpPostedFileBase> pictures)
    {

        //int sayi = resimler.Count();
        ViewBag.a = "abcsados";

        return PartialView("veriler",ViewBag.a);
    }

1 Answers1

0

You cannot upload files using AJAX. This is not supported. If you want to do that you could either use some file upload plugin such as Uploadify or Blueimp File Upload or use the HTML 5 File API if the client browser supports it.

Answer from

Ahmed Sunny
  • 2,160
  • 1
  • 21
  • 27