I want to do a fileupload with MVC and jQuery but my paremter is null. In my jQuery I am getting the form data and assigning it a variable and then POSTING it to an ActionResult. My parameter is null and I am not sure if I am passing the data correctly.
HTML
<table>
                <tr>
                    <td><img src="@Url.Content("~/AMTImages/UserAvatar.png")" width="64" height="64" style="border: thin solid" /></td>
                    <td></td>
                    <td></td>
                    <td>
                        <form enctype="multipart/form-data" id="imageUploadForm">
                            <table>
                                <tr>
                                    <td>@Html.LabelFor(m => m.DisplayName, "Display Name: ")</td>
                                    <td style="padding-left: 10px;">@Html.TextBoxFor(m => m.DisplayName)</td>
                                </tr>
                                <tr>
                                    <td>@Html.LabelFor(m => m.UserImage, "User Image: ")</td>
                                    <td style="padding-left: 10px; float: right;">@Html.TextBoxFor(m => m.UserImage, new { type = "file", accept = "image/*" })</td>
                                </tr>
                            </table>
                        </form>
                    </td>
                    <td>
                        <table style="display:none;">
                            <tr>
                                <td>
                                    <progress></progress>
                                </td>
                            </tr>
                        </table>
                    </td>
                </tr>
            </table>
JavaScript
$(':file').change(function () {
    var file = this.files[0];
    $.ajax({
        url: '@Url.Action("UploadImage", "User")',  //Server script to process data
        type: 'POST',
        data: file,
        beforeSend: function() {  
        },
        success: function () {
        },
        error: function () {
        },
        processData: false,
        contentType: file.type
    });
});
ActionResult
 public ActionResult UploadImage(HttpPostedFileBase file)
        {
            if (file != null && file.ContentLength > 0)
                try
                {
                    string path = Path.Combine(Server.MapPath("~/Images"),
                                               Path.GetFileName(file.FileName));
                    file.SaveAs(path);
                    ViewBag.Message = "File uploaded successfully";
                }
                catch (Exception ex)
                {
                    ViewBag.Message = "ERROR:" + ex.Message.ToString();
                }
            else
            {
                ViewBag.Message = "You have not specified a file.";
            }
            return View();
        }
 
    