2012-03-20 43 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"); 
} 
相关问题