在我的MVC应用程序中,我使用以下代码来上传文件。
模型
public HttpPostedFileBase File { get; set; }
视图
@Html.TextBoxFor(m => m.File, new { type = "file" })
一切运作正常.. 但我正在尝试将结果字段转换为 byte[]。我应该怎么做?
控制器
public ActionResult ManagePhotos(ManagePhotos model)
{
if (ModelState.IsValid)
{
byte[] image = model.File; //Its not working .How can convert this to byte array
}
}
MemoryStream ms = new MemoryStream(); img.Save(ms, ImageFormat.Jpeg); model.SiteLogo = ms.ToArray();```
- VoodooChildmodel.File.InputStream.Position = 0;
才能让它正常工作。 - ManishinputStream
有了一个using语句(顺便说一下,不是指令),两者都将引用同一个对象。你为什么想要两次处理它? - Jon Skeet