How would you validate a checkbox in ASP.Net MVC 2?

前端 未结 4 1641
庸人自扰
庸人自扰 2021-01-05 03:09

Using MVC2, I have a simple ViewModel that contains a bool field that is rendered on the view as a checkbox. I would like to validate that the user checked the box. The [R

4条回答
  •  南笙
    南笙 (楼主)
    2021-01-05 03:50

    I too am looking for a way to have the model binder correctly handle check boxes with Boolean values. In the mean time I'm using this in the Actions:

    Object.Property = !String.IsNullOrEmpty(Request.Form["NAME"]);
    

    Maybe this will be of some use to you.

提交回复
热议问题