提交表单时从 nop4.0 中的 Iformcollection 获取 Null 值

Value getting Null from Iformcollection in nop4.0 when submit the form

我想要来自 Iformcollection 的数据在 nopCommerce 4.0 中得到空值。

这是我在控制器中的 post 方法

[HttpPost]
public ActionResult UpdateCart(int Id, IFormCollection form)
{
  var setting = settingService.LoadSetting<DemoSetting>(_storeContext.CurrentStore.Id);

  //Check plugin is enabled or not
  if (!_setting.DemoSettingEnabled)
      return Content("");

  //Check null value
  if Id,<= 0)
    throw new ArgumentNullException("Id,");

这是我的视图页面,我可以从中 post 数据

 <form asp-controller="DemoDiscounts" asp-action="UpdateCart" asp-antiforgery="true"
          asp-route-Id="@Model.Id" asp-route-id="product-attributes-form" > 

请问大家有解决办法吗?

嘿你可以试试这个希望对你有帮助

<form method="post" asp-controller="YourControllerName" asp-action="YourActionName" asp-route-Id="@Model.Id" id="product-attributes-form" role="form">

最重要的是你忘了Method="Post" 给了id="product-attributes-form" role="form"希望对你有帮助

您需要在标签中添加角色参数

role="form"

<form method="post"  role="form">

...
...
</form>