本文介绍了错误:true,false不是布尔值的有效值...的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的页面上有一个复选框,如下所示:



@ Html.CheckBoxFor(x => x.MyBoolValue)



当我检查它为True并提交此视图时,它会产生错误。



我找到了虚假的控制器中的值。



内部异常是:

{true,false不是布尔值的有效值。}



所以请建议我如何解决它..

I have a checkbox on my page, created as such:

@Html.CheckBoxFor(x => x.MyBoolValue)

When i am Checking it to True and submiting this view then it is generating an error.

and i have found the "false" value in the controller.

The inner exception is:
{"true,false is not a valid value for Boolean."}

So Please suggest me how to resolve it..

推荐答案

[HttpPost]
      public ActionResult Index(FormCollection form)
      {
          bool MyBoolValue= Convert.ToBoolean(form["MyBoolValue"].Split(',')[0]);
          return View();
      }





其他方式



查看是





other way

View is

@Html.CheckBoxFor(x => x.MyBoolValue, Model.MyBoolValue)







[HttpPost]
      public ActionResult Index(Modal model)
      {
          bool MyBoolValue= Convert.ToBoolean(model.MyBoolValue);
          return View();
      }



这篇关于错误:true,false不是布尔值的有效值...的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-22 16:06