问题描述
控制器code看起来像
the controller code looks like
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;
}
}
}
现在我想,如何生成表格操作方法
这将指向详细信息
操作方法,并通过枚举价值如 EmployeeType.RecruitmentOffice或EmployeeType.ResearchInstitute
now i want that how to generate form action method
which will point to Details
action method and pass the enum value like EmployeeType.RecruitmentOffice or EmployeeType.ResearchInstitute
和当我再次将调用该操作方法,通过的jQuery
然后我怎么能传递参数中的id和放大器; EmployeeType
。
and again when i will call that action method by jquery
then how could i pass parameter for id & EmployeeType
.
请与样品code讨论。谢谢
please discuss with sample code. thanks
推荐答案
有关发送为串什么
并转换为枚举
What about sending as string
and convert to enum
public ActionResult Details(int id, string type)
{
EmployeeType empType= (EmployeeType) Enum.Parse(
typeof(EmployeeType), type, true );
}
或做写自定义模型粘合剂。
or do write the custom model binder.
的 注意:的请求参数是字符串
Note: Request params are string
这篇关于如何从以ASP.Net MVC模式通过枚举的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!