Tho*_*mas 4 c# asp.net-mvc enums
控制器代码看起来像
public class EmployeeController : Controller
{
public enum EmployeeType
{
RecruitmentOffice,
ResearchInstitute
}
public ActionResult Details(int id, EmployeeType type)
{
switch (type)
{
case EmployeeType.RecruitmentOffice:
// load repository
// load domain object
// load view specific to recruitment office
break;
case EmployeeType.ResearchInstitute:
// load repository
// load domain object
// load view specific to recruitment office
break;
}
}
}
Run Code Online (Sandbox Code Playgroud)
现在我想要如何生成form action method哪些将指向Details动作方法并传递枚举值EmployeeType.RecruitmentOffice or EmployeeType.ResearchInstitute
再次当我将调用该动作方法时,我jquery怎么能传递参数for id & EmployeeType.
请与示例代码讨论.谢谢
Mur*_*san 10
怎么样发送string和转换为枚举
public ActionResult Details(int id, string type)
{
EmployeeType empType= (EmployeeType) Enum.Parse(
typeof(EmployeeType), type, true );
}
Run Code Online (Sandbox Code Playgroud)
或者写自定义模型绑定器.
注意:请求参数是字符串