2010-02-08 62 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);