I have an entity called Invoice that I am extending for data annotations
[MetadataType(typeof(InvoiceMetadata))]
public partial class Invoice
{
// Note this class has nothing in it. It's just here to add the class-level attribute.
}
public class InvoiceMetadata
{
// Name the field the same as EF named the property - "FirstName" for example.
// Also, the type needs to match. Basically just redeclare it.
// Note that this is a field. I think it can be a property too, but fields definitely should work.
[HiddenInput]
public int ID { get; set; }
[Required]
[UIHint("InvoiceType")]
[Display(Name = "Invoice Type")]
public string Status { get; set; }
[DisplayFormat(NullDisplayText = "(null value)")]
public Supplier Supplier { get; set; }
}
The Uhint[InvoiceType] causes the InvoiceType Editor Template to be loaded for this element.This templates is defined as
@model System.String
@{
IDictionary<string, string> myDictionary = new Dictionary<string, string> {
{ "N", "New" }
, { "A", "Approved" },
{"H","On Hold"}
};
SelectList projecttypes= new SelectList(myDictionary,"Key","Value");
@Html.DropDownListFor(model=>model,projecttypes)
}
i have many such hardcoded status lists in my program.I say hardcoded because they are not fetched from the database. Is there any other way to create templates for drop downs? How do I declare an enum in the model and have the drop down load the enum without having to pass it through a view model ?