【发布时间】:2011-08-04 11:19:18
【问题描述】:
我认为这些标签几乎说明了我的要求..
我一直在努力上传文件。我需要实现的是打开一个文件上传对话框并将其保存到数据库,所以没什么太花哨的。 基本文件上传非常容易。只需使用正确的加密和输入类型文件形成。但是,当我将表单插入对话框时,出现问题并且 Post 中没有任何内容。我尝试添加文件名等测试参数,效果很好。但是实际文件在帖子中丢失了。
这里有一些代码:
表格:
@using (Html.BeginForm("Edit", "Home", FormMethod.Post,
new { enctype = "multipart/form-data" })){
<label for="Name">Filename: </label>
<input type="text" name="name" id="name"/>
<input type="file" name="file" id="file" />
<input type="submit"/>
}
控制器:
public ActionResult Edit(Attachment model)
{
var strLen = Convert.ToInt32(model.file.InputStream.Length);
var strArr = new byte[strLen];
model.file.InputStream.Read(strArr, 0, strLen);
return View();
}
编辑:
型号:
public class Attachment
{
public string Name { get; set; }
public HttpPostedFileBase file{ get; set; }
}
此表单在对话框内。
【问题讨论】:
标签: asp.net-mvc file-upload jquery-ui-dialog