如何将枚举从MVC模型和控制器传递给KnockOutJS模型

时间:2018-06-03 16:38:41

标签: asp.net-mvc enums

我对我的枚举有点落后,并希望了解如何通过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)
}

0 个答案:

没有答案