2010-02-08 61 views
0

我有一个表格,它允许我上传一张图片加上一些其他数据..在我的数据库中,我只保存一个字符串的文件名...现在,当我编辑同样的模式,我应该只让的UpdateModel做的工作或我指定帮助与asp.net mvc UpdateModel与文件上传

modelobject.picture=file.Filename 

某处有问题,我的编辑形式和林不知道究竟如何调试的UpdateModel方法来查找错误但是我猜测它与此有关。

我刚刚意识到异常我得到的是“行未找到或更改”,但它不告诉我哪个行.... 表Im编辑有许多其他值,但我不想改变任何这些,所以它们不包含在窗体中...并且UpdateModel正在接收它应该更新的字段参数

+0

请重新填写。我完全被这个问题弄糊涂了。 – hackerhasid 2010-02-08 19:09:21

回答

0

让您的操作方法中的(或其中一个)参数成为您试图保存到数据库的模型。您的发布表单需要enctype =“multipart/form-data”属性。尝试这个。

//pass in model or use UpdateModel to get non-file info into your model object. 

HttpPostedFileBase document = Request.Files[0]; 

if (document != null && document.ContentLength > 0) 
{ 
    document.SaveAs(document.FileName); 

    model.FileName = document.FileName; 
} 
SaveModelToDB(model);