Error assigning null to a nullable int - “The value 'null' is not valid for property”

后端 未结 6 767
耶瑟儿~
耶瑟儿~ 2020-12-28 16:50

I have this property in my view model:

[DisplayName(\"Region\")]
public int? RegionId { get; set; }

I pass my view model to my controller,

6条回答
  •  孤城傲影
    2020-12-28 17:41

    I have a feeling the problem lies somewhere out of the sample code you have shown. I have created a sample application that just creates a form and has a nullable field, but it works as expected. I would start eliminating other variables in your setup until you can to a working ViewModel with a nullable property, and you should be able to identify what is causing the problem.

提交回复
热议问题