I have a ProjectsModel as a viewmodel:
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; }
}
And I have Project as a model:
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; }
}
}
As you see, I have the enum in my project.cs and here is my controller:
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);
}
I am trying to get PriorityForProject method's value. From the controller, as you see, I can get the byte type which returns a number. How can I reach the value of it ?
Just cast:
TheProjects x = ...;
PriorityForProject priority = (PriorityForProject) x.Priority;
(I'd strongly advise you to rename the TheProjects
type though - that's a really unwieldy, unidiomatic name...)
See more on this question at Stackoverflow