How do I get jQuery's Uploadify plugin to work with ASP.NET MVC?

前端 未结 6 1349
梦如初夏
梦如初夏 2020-12-04 09:37

I\'m in the process of trying to get the jQuery plugin, Uploadify, to work with ASP.NET MVC.

I\'ve got the plugin showing up fine with the following JavaScript snipp

6条回答
  •  天涯浪人
    2020-12-04 10:26

    Here is my simple Razor View (The Layout master has the Javascript bundles)

    @{
    ViewBag.Title = "Upload Email CSV";
    Layout = "~/Views/Shared/_Layout.cshtml";
    }
    
    
    
    

    Upload a comma separated list of email addresses

    @using (Html.BeginForm("UploadEmailCSV", "UploadFile", FormMethod.Post, new { @class = "form-horizontal", @enctype = "multipart/form-data", @id = "frmUploadFiles" })) { }

    Here is the Contoller Method

    public ActionResult UploadEmailCSV()
        {
            var uploadedFile = Request.Files["Filedata"];
    
            if (uploadedFile != null && uploadedFile.ContentLength > 0)
            {
                var filePath = Path.Combine(Server.MapPath("~/UploadedFiles"), string.Format("{0}_{1}{2}", Path.GetFileNameWithoutExtension(uploadedFile.FileName), DateTime.Now.Ticks, Path.GetExtension(uploadedFile.FileName)));
                uploadedFile.SaveAs(filePath);
                return Content(string.Format("{0}_{1}{2}", Path.GetFileNameWithoutExtension(uploadedFile.FileName), DateTime.Now.Ticks, Path.GetExtension(uploadedFile.FileName)));
    
            }
            return Content("Error Uploading file!");
        }
    

    Thats it!

提交回复
热议问题