Within an admin page I originally was generating several checkboxes within a view as per below:
Model:
public class Foo
{
public const string Bar = "SomeString";
}
View:
@Html.CheckBox(Foo.Bar)
@Html.Label(Foo.Bar)
However, I wanted to change the display name of several of the checkboxes, so I created a view model (to later add a display name attribute):
public class FooViewModel
{
public string Bar
{
get { return Foo.Bar; }
}
}
And modified the view:
@Html.CheckBox(Model.Bar)
@Html.LabelFor(m => m.Bar)
However, the view is now generating an error when rendering the checkbox:
String was not recognized as a valid Boolean
Note, that if I change the property name within the view model to anything other than "Bar" the view is rendered correct. EG:
public class FooViewModel
{
public string WTF
{
get { return Foo.Bar; }
}
}
@Html.CheckBox(Model.WTF)
@Html.LabelFor(m => m.WTF)
Can anybody explain to me why this error is occurring if my viewmodel property is named "Bar"?
Edit: I have updated my question slightly seeing as how, i'm generating some confusion. The view is used as a search form and the checkboxes are simply used for selecting "search critera".
I'm generating the checkbox in this fashion so the name / id of the checkbox is related to corresponding business logic within the controller.
I'm aware that code will not compile if property name / field name within the same class are identical. That is not the issue, as i'm simply initializing a property from constant within a different namespace.
staticone? How did that even compile?