Pass values of checkBox to controller action in asp.net mvc4

后端 未结 12 1546
长发绾君心
长发绾君心 2020-12-14 00:31

I want to test if the checkbox is checked or not from my action method, what i need is to pass checkbox value from view to controller.

This is my view:



        
12条回答
  •  情歌与酒
    2020-12-14 01:14

    try using form collection

     
    
    [HttpPost]
    public ActionResult Index(FormCollection collection)
    {
         if(!string.IsNullOrEmpty(collection["checkResp"])
         {
            string checkResp=collection["checkResp"];
            bool checkRespB=Convert.ToBoolean(checkResp);
         }
    
    }
    

提交回复
热议问题