简体   繁体   中英

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

I want data from Iformcollection in nopCommerce 4.0 it getting null value.

This is my post method in controller

[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,");

This is my view page from which i can post data

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

Can you please suggest if any one have solution?

Hey You can try this hope so it will helpful to you

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

Main thing you forgot Method="Post" and give id="product-attributes-form" role="form" hope so it can helpful to you

You need to add role parameter in tag

ie role="form"

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

...
...
</form>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM