Reputation: 268
I can retrieve a string but I can't retrieve a decimal/int/float.
When retrieving the the string I used this.
customer.FirstName = formCollection["FirstName"];
customer.LastName = formCollection["LastName"];
Or
FirstName = formCollection["FirstName"],
LastName = formCollection["LastName"]
Then I tried it to a decimal/foat/integer, but having an error "Cannot implicitly convert type 'string' to 'int' "
Amount= formCollection["Amount"]
so I try this
Amount= int32.Parse.formCollection["Amount"]
Amount= int32.TryParse.formCollection["Amount"]
but it's overloading. Can someone know how to collect a int/float/decimal from view to controller??
Upvotes: 3
Views: 2654
Reputation: 301
formCollection["Amount"]
is a string, because you use an <input type="text" />
I guess. int32.Parse(string s)
wants a string. So just write:
Amount = Int32.Parse(formCollection["Amount"]);
Upvotes: 4