Anfrage.Dateien, die Leer ist in MVC-Datei hochladen

Ich habe das gleiche Problem

@using (Html.BeginForm("CreateRequest", "SupportRequest", FormMethod.Post, new { id = "frmStemplate", enctype = "multipart/form-data" }))
{
  <td><input type="file" name="FirstFile" id="FirstFile" class="button"  /> 
  <input  type="button" class="button" id="FirstFileupload"  value="upload" onclick="Javascript:DocumentUpload();"/>
}

<script language="javascript" type="text/javascript">
    function DocumentUpload()
    {
        var BrowseFile = $('#FirstFile').val();

        if (BrowseFile != null && BrowseFile != "") {
            alert(BrowseFile);
            $.ajax({
                type: 'POST',
                dataType: 'json',
                url: '@Url.Content("~/SupportRequest/UploadFiles")?fileElementId=' + BrowseFile,
                success: function (data) {
                    alert('Hi'); //debugger;
                    if (data.Result == "SUCCESS") {
                        alert('Hi');
                    }
                    else {
                        ShowInfo('Document Uploaded Successfully');
                    }
                }
            });
        }
    }
</script>

Auf der controller-Seite habe ich:

[AcceptVerbs(HttpVerbs.Post)]
public ActionResult UploadFiles(string fileElementId, FormCollection formColl)
{
    var FirstFile = Request.Files;
    foreach (string upload in Request.Files)
    {
        if (!Request.Files[upload].HasFile()) continue;
        string path = AppDomain.CurrentDomain.BaseDirectory + "uploads/";
        string filename = Path.GetFileName(Request.Files[upload].FileName);
        Request.Files[upload].SaveAs(Path.Combine(path, filename));
    }
    return Json(new { Filename = "" });
}

Aber meine Request.Files ist immer null.

Ich habe versucht, verschiedene Dinge, wie das ändern der code Request.Files["FirstFile"] usw. Jedes mal, die Datei-collection ist leer.

InformationsquelleAutor Shrilata Ellaboina | 2011-12-12

Schreibe einen Kommentar