我正在使用nopCommerce。我正在制作插件。我想在表Look_Product_Mapping中添加所选产品。为此,我使用了popup(ProductAddPopup.cshtml),比如在类别中添加产品。当我保存产品以添加所选产品时。它执行ProductAddPopup方法。但它获取所有参数的空值,并成功插入新记录。
我已将此代码用于"添加新产品"按钮将打开一个弹出窗口。
<input type="submit" id="btnAddNewProduct" name="btnAddNewProduct" value="@T("Admin.Catalog.Categories.Products.AddNew")" onclick="javascript:OpenWindow('@(Url.Action("ProductAddPopup", "LookBook", new {lookId = Model.Id, btnId = "btnRefreshProducts", formId = "products-form" })) ', 800, 800, true); return false;" class="t-button" />
保存按钮代码:
<input type="submit" name="save" class="t-button" value="@T("Admin.Common.Save")" />
ProductAddPopup方法代码:
[HttpPost]
[FormValueRequired("save")]
public ActionResult ProductAddPopup(string btnId, string formId, AddLookProductModel model)
{
if (!_permissionService.Authorize(StandardPermissionProvider.ManageCategories))
return AccessDeniedView();
if (model.SelectedProductIds != null)
{
foreach (int id in model.SelectedProductIds)
{
var product = _productService.GetProductById(id);
if (product != null)
{
var existingProductLooks = _lookService.GetProductLookByLookId(model.LookId, 0, int.MaxValue, true);
if (existingProductLooks.FindProductLook(id, model.LookId) == null)
{
_lookService.InsertLookProduct(
new Look_Product_Mapping()
{
LookId = model.LookId,
ProductId = id,
DisplayOrder = 1
});
}
}
}
}
ViewBag.RefreshPage = true;
ViewBag.btnId = btnId;
ViewBag.formId = formId;
return View(model);
}
我做错了吗? 请帮我解决这个问题。 提前谢谢
答案 0 :(得分:1)
我相信您的javascript方法 OpenWindow 最终会使用window.open
,并且会使用GET
协议加载内容
尝试使用HttpGet
[HttpGet]
[FormValueRequired("save")]
public ActionResult ProductAddPopup(string btnId, string formId,
ddLookProductModel model)
{
}