Bind Checkboxes to int array/enumerable in MVC

后端 未结 3 1618
慢半拍i
慢半拍i 2021-02-05 08:46
@Html.CheckBox(\"orderNumbers\", new { value = 1 })
@Html.CheckBox(\"orderNumbers\", new { value = 2 })
@Html.CheckBox(\"orderNumbers\", new { value = 3 })
@Html.CheckBo         


        
3条回答
  •  独厮守ぢ
    2021-02-05 09:14

    You can get all the checked values by the following way.

    Controller code :

        public ActionResult Index()
        {            
            return View();
        }
    
        [AcceptVerbs(HttpVerbs.Post)]
        public ActionResult Index(string[] orderNumbers)
        {
            return View();
        }
    

    View Code :

    @using (Html.BeginForm())
    {
        
        
        
        
        
    
        
    }
    

    Please keep one thing in my mind that, you need to give same name to all checkboxes. In array you will get values for all checked checkboxes.

提交回复
热议问题