我对我的枚举有点落后,并希望了解如何通过JsonResult从mvc控制器传递枚举以填充下拉列表。我的所有其他财产都通过了。它唯一的枚举如下:
枚举
public enum SpeciesType{
Mammal = 1;
Reptile = 2; }
视图模型
public int Id {get; set;}
public string AnimalName {get; set;}
public DateTime DateOfRecording { get; set; }
public SpeciesType Species { get; set; }
控制器
public JsonResult EditAnimalRecord(int animalId){
var model = new EditViewModel();
var record = (Linq statement in here);
if(record.Id > 104){
model.Id = record.Id;
model.AniamlName = record.Name;
model.DateOfRecording = record.DateEntered;
model.Species = ???(Need to pass enums here) to populate dropdown via JS
}
return Json(model, JsonRequestBehavior.AllowGet)
}