【问题标题】:nopCommerce 2.40 Admin Product Edit AdditionnopCommerce 2.40 管理员产品编辑添加
【发布时间】:2012-03-20 17:12:43
【问题描述】:

希望我能在这里取得一些进展,因为 nopCommerce 论坛一直对我的帖子保持沉默。我目前的情况是,对于我们商店中的每个产品,我们(管理员)需要上传一个特定的文档,并在最终用户浏览产品详细信息部分时通过链接和下载的方式将该文档显示给最终用户。

所以我想我会拆分这个项目并首先尝试从管理区域开发上传功能。

如果其他人可以提供帮助但不知道 nopCommerce,它是一个 ASP.NET MVC 3 项目。对于那些已经拥有 nopCommerce 的人,请在下面查看如何导航并将我的代码添加到特定文件中。

1.如何在产品编辑中添加标签:

a.Inside Nop.Admin

i.导航到视图 -> _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");
}

现在,我遇到的问题是:我现在可以在产品编辑中看到选项卡,但我无法上传文件。它提交查询,但只是刷新页面并返回产品列表。没有文件上传。如果可以,请协助我尝试将文件正确上传到我指定的路径。再次感谢您的协助。

我已经从头开始尝试了一个上传项目,它确实可以正常工作,但由于某种原因,在这里,它无法正常工作。

【问题讨论】:

    标签: admin product nopcommerce


    【解决方案1】:

    您可能需要表单的操作参数中的操作 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");
    }
    

    【讨论】:

      【解决方案2】:

      可能有点晚了,但我为此做了一个插件。可以在github上找到

      https://github.com/johanlasses/nopcommerce-product-files-plugin

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2014-02-18
        • 2018-11-24
        • 2020-02-15
        • 1970-01-01
        • 1970-01-01
        • 2019-03-13
        • 1970-01-01
        相关资源
        最近更新 更多