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) %>
精彩评论