public enum Employee
{
FT,
PT,
}
これはうまくいきません
public ActionResult Index(Employee s = Employee.PT)
{
ViewData["Message"] = s.ToString();
return View("MyView");
}
例外の詳細: System.ArgumentException: パラメーター ディクショナリには、'SampleControllerEx.Controllers.HomeController' のメソッド 'System.Web.Mvc.ActionResult Index(SampleControllerEx.Controllers.Employee)' のパラメーター 's' の無効なエントリが含まれています。ディクショナリには「System.Int32」型の値が含まれていますが、パラメーターには「SampleControllerEx.Controllers.Employee」型の値が必要です。パラメータ名: パラメータ
しかし、以下の作品は、
public ActionResult Index([DefaultValue(Employee.PT)] Employee s)
{
ViewData["Message"] = s.ToString();
return View("MyView");
}
オプションのパラメーター (4.0) がサポートしていないのに、'DefaultValue' がカスタム列挙型のみをサポートする理由を教えてください。