我在我的模式下创建了一个枚举。如何使用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