2 wzg csdn wzg_csdn 于 2016.01.22 00:37 提问

MVC Ajax.Begin()异步上传不了,求解救

View代码:

         @using (Ajax.BeginForm("ProcessImagUpload", "Async", new AjaxOptions()
        {
            HttpMethod = "post",
            OnSuccess = "afterUpload"
        }, new { enctype = "multipart/form-data" }))
        {
            <input type="file" name="imgFile" />
            <input type="submit" value="异步上传图片" />
        }

Control代码
public ActionResult ProcessImagUpload()
{
var file = Request.Files["imgFile"];

        string path ="/Upload/"+Guid.NewGuid().ToString()+ file.FileName;
        file.SaveAs(Request.MapPath(path));

        return Content(path);
    }

查看请求报文

请求 URL:http://localhost:14092/Async/ProcessImagUpload?Length=5
请求方式:POST
状态代码:500 Internal Server Error
请求 HTTP 报头查看源代码
Accept:*/*
Accept-Encoding:gzip,deflate
Accept-Language:zh-CN
Connection:keep-alive
Content-Length:31
Content-Type:application/x-www-form-urlencoded; charset=UTF-8

大半夜的求大神拯救

2个回答

caozhy
caozhy   Ds   Rxr 2016.01.22 02:59

string path ="/Upload/"+Guid.NewGuid().ToString()+ file.FileName;
->
string path ="~/Upload/"+Guid.NewGuid().ToString()+ file.FileName;
看看

wzg_csdn
wzg_csdn 不行的
接近 2 年之前 回复
HappyGirlFriend
HappyGirlFriend   2016.01.25 14:39

你的文件夹应该不存在吧,
if (!Directory.Exists(path))
{
Directory.CreateDirectory(path);
}
或是
string path ="/Upload/"+Guid.NewGuid().ToString()+“/”+ file.FileName;?

Csdn user default icon
上传中...
上传图片
插入图片