希望我能在这里取得一些进展,因为nopCommerce论坛对我的帖子保持沉默。我目前的情况是,对于我们商店中的每个产品,我们(管理员)需要上传特定文档,并在浏览产品详细信息部分时通过链接和下载向最终用户显示该文档。
所以我想我会砍掉这个项目并首先尝试从管理区域开发上传功能。
如果其他人可以提供帮助但不知道nopCommerce,那么它就是一个ASP.NET MVC 3项目。对于那些已经拥有nopCommerce的用户,请在下面查看如何导航并将我的代码添加到特定文件中。
1.如何向产品编辑添加选项卡:
a.Inside Nop.Admin
i.Navigate to Views - > _CreateOrUpdate.cshtml
b。在第24行之后添加TabPanel
x.Add().Text(T("Admin.Catalog.Products.ProductDocuments").Text).Content(TabProductDocuments().ToHtmlString());
c。在第772行创建'TabProductDocuments'帮助方法
@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。将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");
}
现在,我遇到的问题是:我现在可以在“产品编辑”中看到该标签,但我无法上传该文件。它提交查询但只刷新页面并返回产品列表。没有上传文件。如果可以,请帮助我尝试将文件正确上传到我指定的路径。再次感谢您的帮助。
我已经尝试过一个上传项目,它确实可以正常工作,但出于某种原因,这里只是不起作用。
答案 0 :(得分:1)
您可能需要在表单的action参数中使用Action url。
<form action="/Admin/Product/Upload/555" method="post" enctype="multipart/form-data">
并重命名您的Action方法以匹配
[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");
}
答案 1 :(得分:1)
可能有点晚了,但我为此做了一个插件。可以在github上找到
https://github.com/johanlasses/nopcommerce-product-files-plugin