0

I have a nullable boolean in a class that I'm using for a model for a partial view. By doing the following:

@Html.CheckBoxFor(p => p.policies.is_a_company.Value, new { @class = "form-control", @Id = "policies.is_a_company", @Name = "policies.is_a_company" })

I've managed to get the 'policies.is_a_company' to be part of the serialized string being posted to the form method in my controller (it was posting it as 'policies.is_a_company_.Value' before). However, I notice the value of 'is_a_company' still ends up being null when I check the controller method. When I serialize the form in the console, the value is either 'true' or 'false' but I've noticed that the booleans that make it to the controller fine are either 'True' or 'False' (upper case first letters). Is there a way I can make the first letters of 'is_a_company' upper case as well?

SuperStormer
  • 4,997
  • 5
  • 25
  • 35

1 Answers1

0

I found a fix, I'm using

@Html.CheckBox("policies.is_a_company", Model.policies.is_a_company ?? false, new { @class = "form-control", @Id = "policies.is_a_company", @Name = "policies.is_a_company" })

now. It works perfectly.

SuperStormer
  • 4,997
  • 5
  • 25
  • 35