1

So now I can retrieve a string and integer

by doing this for string

 LastName = formCollection["LastName"]

and for int

Amount = int.Parse(formCollection["Amount"])

My problem now is for enum. I tried this, still have an error

  Issuer = Enum.Parse(formCollection["Issuer"]);
  Issuer = Enum.Parse(typeof(Issuer), formCollection["Issuer"]);
Woshooo
  • 250
  • 1
  • 2
  • 18
  • what is the error message? – Ehsan Sajjad Mar 10 '17 at 20:16
  • an explicit convertion – Woshooo Mar 10 '17 at 20:19
  • you should have added the error message in the question that saves other users time to figure out the actual problem – Ehsan Sajjad Mar 10 '17 at 20:21
  • okay I will, next time, thanks again – Woshooo Mar 10 '17 at 20:23
  • You should never use `FormCollection`. Bind to your model! (and its all handled automatically - the `M` in MVC is for Model) –  Mar 10 '17 at 21:45
  • @StephenMuecke I know but i'm using sdk model... don't know how bind it, if the database is in third party... – Woshooo Mar 11 '17 at 12:55
  • That has nothing to do with it. Create a view model containing a property `Issuer Issuer`, int Amount, string LastName` etc (and use the strongly type `HtmlHelper` methods to bind to it and then add a parameter for that model in the POST method, then map it to your data model) –  Mar 11 '17 at 22:59

1 Answers1

2

You will need to explicitly cast the result,as Enum.Parse() method returns back instance of type Object, so you will need convert back to type of specific Enum type in this case Issuer, so you just need to add explicit casting like:

Issuer = (Issuer)Enum.Parse(typeof(Issuer), formCollection["Issuer"]);
Ehsan Sajjad
  • 61,834
  • 16
  • 105
  • 160