我在我的模式下創建了一個枚舉。如何使用AngularJs顯示枚舉值
public enum Color
{
Green,
Black,
Red,
Silver,
Yellow,
White,
Grey,
}
因此,我在主類中使用了enum。
public class MotorDetails
{
public int Id { get; set; }
public string Name { get; set; }
public string Make { get; set; }
public string Model { get; set; }
public string Year { get; set; }
public string Kilometers { get; set; }
public Color Color { get; set; }
}
我然後像
context.MotorDetails.AddOrUpdate(x => x.Id, new MotorDetails()
{
Name = "Accord",
Make = "Honda",
Model = "Accord",
Year = r.Next(1980,2016).ToString(),
Kilometers = r.Next(50000, 200000).ToString(),
Color = (Color)r.Next(1,7),
}
種子數據因此,在數據庫B/w的1,7的任意值被保存用於顏色。 這很好。
現在我是該數據從控制器返回到我的視圖
public List<MotorDetails> getByMake(string make, int minPrice, int maxPrice)
{
List<MotorDetails> motor = db.MotorDetails.Where(x => x.Make == make && x.Price >= minPrice && x.Price <= maxPrice).ToList();
return motor;
}
問題: 它返回一個整數顏色到我的視圖,因此數表示上視圖。 我想顯示給定數字的顏色名稱。
我使用的是angularJs,這裏是我的代碼。
<div>
<table class="table">
<tr>
<th>Name</th>
<th>Make</th>
<th>Model</th>
<th>Year</th>
<th>Kilometers</th>
<th>Price</th>
<th>Color</th>
</tr>
<tr ng-repeat="m in motors">
<td>{{m.Name}}</td>
<td>{{m.Make}}</td>
<td>{{m.Model}}</td>
<td>{{m.Year}}</td>
<td>{{m.Kilometers}}</td>
<td>{{m.Price}}</td>
<td>{{m.Color}}</td>
</tr>
</table>
</div>
謝謝,它的好方法,並解決了我的問題。 – simbada