How to get checkbox value from FormCollection?

后端 未结 5 455
耶瑟儿~
耶瑟儿~ 2021-01-02 03:18

I have a checkbox and button:

@using(Html.BeginForm())
{
    
5条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-02 03:33

    Try this, it solved this same issue for me. Thought I would share it in case others came upon this issue in the future.

    [HttpPost]
    public ActionResult Index(FormCollection collection)
    {
        Boolean tempValue = collection["showAll"] != null ? true : false;
        TempData["showAll"] = tempValue;
    
        ... 
        something
        ...
    }
    

提交回复
热议问题