nopcommercenopcommerce-4.0

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?


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