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: The parameters dictionary contains an invalid entry for parameter 's' for method 'System.Web.Mvc.ActionResult Index(SampleControllerEx.Controllers.Employee)' in 'SampleControllerEx.Controllers.HomeController'. The dictionary contains a value of type 'System.Int32', but the parameter requires a value of type 'SampleControllerEx.Controllers.Employee'. Parameter name: parameters
But below one works,
public ActionResult Index([DefaultValue(Employee.PT)] Employee s)
{
ViewData["Message"] = s.ToString();
return View("MyView");
}
May I know why 'DefaultValue' only supports custom enum, where optional parameter(4.0) doesn't support it?
if ((s ?? Employee.PT) == Employee.PT) { // some code }