How to set order of appearance for fields when using Html.EditorFor in MVC 2?
-
18-09-2019 - |
Question
I have the following classes in my Model:
public abstract class Entity : IEntity
{
[ScaffoldColumn(false)]
public int Id { get; set; }
[Required,StringLength(500)]
public string Name { get; set; }
}
and
public class Model : SortableEntity
{
[Required]
public ModelType Type { get; set; }
[ListRequired]
public List<Producer> Producers { get; set; }
public List<PrintArea> PrintAreas { get; set; }
public List<Color> Colors { get; set; }
}
To display the "Model" class in the view I simply call Html.EditorFor(model=>model), but the "Name" property of the base class is rendered last, which is not the desired behaviour.
Is it possible to influenece on the order of displayed fields somehow?
Solution
I've not been able to find an attribute for that, so your options are:
1) create one, and then revise the base Object.ascx template to account for it, or 2) create a custom editor template for your classes that explicitly put stuff in the order you want.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow