c# - Custom enum as optional parameter -


  public enum employee     {         ft,         pt,     } 

this doesn't work

  public actionresult index(employee s = employee.pt)         {             viewdata["message"] = s.tostring();              return view("myview");         } 

exception details: system.argumentexception: parameters dictionary contains invalid entry parameter 's' method 'system.web.mvc.actionresult index(samplecontrollerex.controllers.employee)' in 'samplecontrollerex.controllers.homecontroller'. dictionary contains value of type 'system.int32', parameter requires value of type 'samplecontrollerex.controllers.employee'. parameter name: parameters

but below 1 works,

public actionresult index([defaultvalue(employee.pt)] employee s)         {             viewdata["message"] = s.tostring();              return view("myview");         } 

may know why 'defaultvalue' supports custom enum, optional parameter(4.0) doesn't support it?

you can in such way:

 public actionresult index(int employeetype)         {             employee s = (employee) employeetype;             viewdata["message"] = s.tostring();              return view("myview");         } 

Comments

Popular posts from this blog

android - getbluetoothservice() called with no bluetoothmanagercallback -

sql - ASP.NET SqlDataSource, like on SelectCommand -

ios - Undefined symbols for architecture armv7: "_OBJC_CLASS_$_SSZipArchive" -