开发者

how to create a checkbox that need to pass string value?

i want to create a check box and that should have to string value?

<%:Html.Ch开发者_运维问答eckBoxFor(model => model.bird)%>
<%:Html.LabelFor(model=>model.bird) %>

i get a error saying string cannot convert to bool?


The problem is because the bird member of your model is not a boolean type.

Add a new bool member (birdBool) to your model. This member can be as follow:

public bool birdBool
{
   get{
      try
      {
         return bool.Parse(this.bird);
      }
      catch{
         return false;
      }
   }
   set{
      this.bird=value.ToString();
   }
}

In your view write this:

<%:Html.CheckBoxFor(model => model.birdBool)%>
<%:Html.LabelFor(model=>model.bird) %>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜