24
I have this property in my view model:
[DisplayName("Region")]
public int? RegionId { get; set; }
I pass my view model to my controller, and it fails at ModelState.IsValid if RegionId is null. If I pass an integer to it, it works fine.
The error message is:
The value 'null' is not valid for Region
I've also tried calling this before I check ModelState.IsValid, but I get the same error:
if (viewModel.RegionId == null)
viewModel.RegionId = (int?)null;
What's the problem here? Why can't I assign null to something that is nullable?