【发布时间】:2015-02-25 17:14:35
【问题描述】:
我有一个 ProjectsModel 作为视图模型:
public IEnumerable<TheProjects> OurProjects { get; set; }
public class TheProjects
{
public int Id { get; set; }
public string ProjectName { get; set; }
public short PhaseCount { get; set; }
public string ProjectOwner { get; set; }
public byte Priority { get; set; }
}
我有 Project 作为模型:
public enum PriorityForProject
{
Acil = 0,
Normal = 1,
Düsük = 2
}
namespace JobTracking.Models
{
public class Project
{
public int Id { get; set; }
public string ProjectName { get; set; }
public int ProjectNo { get; set; }
public string ProjectType { get; set; }
public string ProjectOwner { get; set; }
public string StartDate { get; set; }
public string EndDate { get; set; }
public string ProjectManager { get; set; }
public string Team { get; set; }
public string ProjectDescription { get; set; }
public PriorityForProject Priority { get; set; }
public string Costs { get; set; }
public string CashExpenditures { get; set; }
public short Sira { get; set; }
}
}
如您所见,我的 project.cs 中有枚举,这是我的控制器:
public ActionResult Index(int S = 1)
{
var itemsPerPage = 100;
var model = new ProjectsModel
{
ItemsPerPage = itemsPerPage,
Page = S,
TotalItems = Db.MyProjects.Count(),
OurProjects = Db.MyProjects.OrderByDescending(o => o.Sira).Skip((S - 1) * itemsPerPage).Take(itemsPerPage)
.Select(s => new ProjectsModel.TheProjects
{
Id = s.Id,
ProjectName = s.ProjectName,
PhaseCount = (short)Db.MyPhases.Where(p => p.Project.Id == s.Id).Count(),
ProjectOwner=s.ProjectOwner,
Priority = (byte)s.Priority
})
};
return View(model);
}
我正在尝试获取 PriorityForProject 方法的值。如您所见,从控制器中,我可以获得返回数字的字节类型。我怎样才能达到它的价值?
【问题讨论】:
-
当
PriorityForProject的基础类型是int时,为什么要为TheProjects.Priority属性使用byte?如果它们是一样的会更干净。 -
是的,我让它们都一样@JonSkeet 谢谢你
标签: c# asp.net-mvc enums