How to pass Enum from view to model ASP.Net MVC

后端 未结 4 1126
广开言路
广开言路 2020-12-15 13:01

the controller code looks like

public class EmployeeController : Controller
{
    public enum EmployeeType
    {
        RecruitmentOffice,
        ResearchI         


        
4条回答
  •  不思量自难忘°
    2020-12-15 13:51

    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

提交回复
热议问题