2012-03-20 162 views
0

希望我能在這裏取得一些進展,因爲nopCommerce論壇對我的文章一直保持沉默。我目前的情況是,對於我們商店中的每種產品,我們(管理員)都需要上傳特定文檔,並通過鏈接和下載將該文檔展示給最終用戶瀏覽產品詳細信息部分。nopCommerce 2.40管理產品編輯加法

所以我想我會砍掉這個項目,首先嚐試從管理區域開發上傳功能。

如果其他人可以幫助但不知道nopCommerce,它是一個ASP.NET MVC 3項目。對於那些已經有nopCommerce的人,請看下面如何導航並將我的代碼添加到特定文件。線24後> _CreateOrUpdate.cshtml

b。增加的TabPanel -

i.Navigate

a.Inside Nop.Admin到瀏覽次數:

1.How的標籤添加到產品編輯

x.Add().Text(T("Admin.Catalog.Products.ProductDocuments").Text).Content(TabProductDocuments().ToHtmlString()); 

c.Create 'TabProductDocuments' 在線幫助方法772

@helper TabProductDocuments() 
{ 
if (Model.Id > 0) 
{ 
<h2>Product Documents</h2> 
<form action="" method="post" enctype="multipart/form-data"> 
<label for="file">Filename:</label> 
<input type="file" name="file" id="file" /> 
<input type="submit" /> 
</form> 
} 
else 
{ 
@T("Admin.Catalog.Products.ProductDocuments.SaveBeforeEdit") 
} 
} 

d.Change ProductDocumentsController.cs更簡單的代碼:現在

public class ProductDocumentsController : BaseNopController 
{ 
[HttpPost] 
public ActionResult Index(HttpPostedFileBase file) 
{ 
if (file.ContentLength > 0) 
{ 
var fileName = Path.GetFileName(file.FileName); 
var path = Path.Combine(HttpContext.Server.MapPath("../Content/files/uploads"), fileName); 
file.SaveAs(path); 
} 
return RedirectToAction("Index"); 
} 

,我遇到的問題是:我現在可以看到的標籤在產品編輯,但我不能上傳文件。它提交查詢,但只刷新頁面並返回到產品列表。沒有文件上傳。如果可以,請協助我嘗試將文件正確上傳到我指定的路徑。再次感謝您的幫助。

我已經嘗試了從頭開始上傳項目,它確實工作正常,但由於某種原因,在這裏,它只是不工作。

回答

1

您可能需要在窗體的操作參數中使用Action url。

<form action="/Admin/Product/Upload/555" method="post" enctype="multipart/form-data"> 

和重命名你的行動方法,以配合

[HttpPost] 
public ActionResult Upload(int productId, HttpPostedFileBase file) 
{ 
    if (file.ContentLength > 0) 
    { 
     var fileName = Path.GetFileName(file.FileName); 
     var path = Path.Combine(HttpContext.Server.MapPath("../Content/files/uploads"), fileName); 
     file.SaveAs(path); 
     //attach the file to the product record in the database 
    } 
    return RedirectToAction("Index"); 
}