我正在从数据库中读取枚举值,然后将其绑定到模型。当我使用 ajax 发布表单时,以某种方式枚举未绑定或模型属性为 null 或零,但它在视图上正确显示。我在下面发布了代码。我使用实体框架和 mvc3
//model code constructor
public CarModel(Car car)
{
State=(CarState)car.State;
//car.State comes in as an int
//etc setting other variables
}
//CarState property
public CarState {get;set;}
//model code
@Html.DisplayFor(m=>m.CarState)
//Controller code()
Save(CarModel car)
{
//I have code that saves the changes
}
我到达“汽车”的那一刻,CarState 没有任何价值。