I am using Mvc 3 and have come across the following scenario:
I've got a view model that has a list of note elemements as a property and I am using the HtmlHelper
extension method EditorFor
to render out the collection. All is working great. However now I need to display the note elements in the reverse order.
Is there a way to tell Mvc to reverse the elements?
// View Models
public class MyViewModel
{
public List<Note> Notes
{
get;
set;
}
}
public class Note
{
public string Username
{
get;
set;
}
public DateTime ChangedDate
{
get;
set;
}
public string Text
{
get;
set;
}
}
The elements are in oldest first order.
I can reverse the order of the elements in the collection to solve the problem which at the moments seems the most logically way to go. However that makes the javascript to insert new notes more complex as that requires the name and id of the html elements to be rewritten.
So I was hoping there maybe some sort of order option for the EditorFor
method.
Another alternate would be to write a custom partial view and update the TemplateInfo.HtmlFieldPrefix
but I like to keep to using the EditorTemplates if I can.