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

602 views Asked by At

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?

2

There are 2 answers

0
ILYAS PATEL On BEST ANSWER

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

0
Raju Paladiya On

You need to add role parameter in tag

i.e. role="form"

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

...
...
</form>