我有这个动作方法
[HttpPost]
public void Test(HttpPostedFileBase file)
{
byte[] image = new byte[file.ContentLength];
file.InputStream.Read(image, 0, image.Length);
}
我想将此操作方法中的字节数组发送到表格列中的sql server数据库....我该怎么办?
答案 0 :(得分:0)
public class MyImage
{
public byte[] Image { get; set; }
}
[HttpPost]
public void Test(HttpPostedFileBase file)
{
byte[] image = new byte[file.ContentLength];
file.InputStream.Read(image, 0, image.Length);
var i = new MyImage { Image = image };
dbcontext.MyEntity.Add(i);
dbcontext.SaveChanges();
}
只需将字节数组保存在实体属性中,它就可以正常工作。