-4
cartitem i = new cartitem() { iid = int.Parse(pid), iqty = int.Parse(pqty)};

got exception

An exception of type 'System.ArgumentNullException' occurred in mscorlib.dll but was not handled in user code

trying to add items in cart using this action method cart()

Alexei Levenkov
  • 98,904
  • 14
  • 127
  • 179
Adnan
  • 1
  • 2

1 Answers1

1

The Exception System.ArgumentNullException is raised by the CLR when the parameter passed in Parse method is null.

Which in your case is either pid or pqty OR both.

Check this Microsoft document for more details.

https://learn.microsoft.com/en-us/dotnet/api/system.int32.parse?view=netframework-4.7.2

I would suggest, add code validating values of both the parameters before you create new object of the item and add it to cart. If any one of them is null or unacceptable value provide a helpful message to user.

Alexei Levenkov
  • 98,904
  • 14
  • 127
  • 179
dj079
  • 1,389
  • 8
  • 14