public async Task UploadFiles(List file)
{
EditorDataResult editorResult = new EditorDataResult();
foreach (var formFile in file)
{
if (formFile.Length > 0)
{
FileInfo fi = new FileInfo(formFile.FileName);
string ext = fi.Extension;
var orgFileName = fi.Name;
var newFileName = Guid.NewGuid() + ext;
var uploads = Path.Combine(_hostingEnvironment.WebRootPath, "你想要上传到文件夹");
var filePath = Path.Combine(uploads, newFileName);
using (var stream = new FileStream(filePath, FileMode.Create))
{
await formFile.CopyToAsync(stream);
}
editorResult.code = 0;
}
else
{
editorResult.code = 1;
}
}
JavascriptSerializer jss = new JavascriptSerializer();
string data = jss.Serialize(editorResult);//转换为Json格式!
return Json(data);
}
model部分 主要就是回调json数据给layui
namespace LayuiMvc.Common.Result
{
public class EditorDataResult
{
public int code { get; set; }
public string msg { get; set; }
public Dictionary data { get; set; }
}
}