Question: I'm trying to pass a file to my aspnet project without using FormData, all the values are sent but the file itself. So I was able to `if ($('#Prop').get(0).files.length === 0` check if theres something in there but I can't send it. The model behind has a `HttpPostedFileBase` property and I was trying to send with :

`$('#Prop').get(0).files`

`$('#Prop').val()`

Not working!

Answer: 
If you are using MVC structure you can use below code:

MVC razar syntax provides **@Ajax.Beginform()**, here you can send "multipart/form-data".

```
@using (Ajax.BeginForm("action", YourController, new { id= Model.Id }, new AjaxOptions {needed options }, new { enctype = "multipart/form-data" }))
{
    <input type="file" id="fileid" name="filename" />
    <input type="submit" value="Modify" />
}

```
Here is the Complete Example,

```html
  <div class="item form-group"> <label class="control-label col-md-3 col-sm-3 col-xs-12" for="logo"> Logo <span class="required">*</span> </label> <div class="col-md-6 col-sm-6 col-xs-12"> <input id="CouncilLogo" class="  col-md-12 col-xs-12" name="Logo"   type="file"  > </div> <div class="col-md-3 col-sm-3 col-xs-12"> </div>  </div>  <div class="ln_solid"></div>  <div class="form-group"> <div class="col-md-6 col-md-offset-3"> <button id="BtnCancel" type="submit" class="btn btn-primary">Cancel</button> <button id="BtnSubmit" type="submit" class="btn btn-success">Submit</button>  </div>  </div>
```

```
<script>
$("#BtnSubmit").click(function () {
var files = $("#Logo").get(0).files; var data = new FormData(); if (files.length > 0) { data.append("file", files[0]); }  $.ajax({ url: "../controllername/SaveImage", type: "Post", data: data,  async: false, contentType: false, processData: false,  success: function (ReturnValue) { if (ReturnValue == "Error") {  alert('Error'); } else {  alert('Success'); } }, error: function (err) {  alert('Something Went Wrong');  }, });
});
</script>

```

Controller code:-

```
 public ActionResult Insert(HttpPostedFileBase file)
    {
        string Output = "";
        string ImageName = "";
        try { ImageName = WebImagePath + " Logo/" + 
        System.IO.Path.GetFileName(file.FileName); }
        catch (Exception e) { }

        if (Output == "")
        {
            try
            {
                string physicalPath = 
              Server.MapPath(ImageName);
                file.SaveAs(physicalPath);
                objData.CouncilLogo = ImageName;                 

                db.ImageMaster.Add(objData);
                db.SaveChanges();
                Output ="Saved"  
            }
            catch (Exception e)
            {
                Output="Error";
            }
        }
        return this.Json(Output);
    }

```