I’m working on a project with .NET / MVC3 / Razor.
I have a form with a multiple select.
When the User press save, how can I get server-side the values in the order they were selected?
Let’s say I have:
<select multiple="multiple">
<option>Volvo</option>
<option>Saab</option>
<option>Mercedes</option>
<option>Audi</option>
</select>
and that the User selects “Audi” and the “Saab”, and the press save.
Currently, server-side, I’m receiving “Saab” and “Audi” as selected values.
I would like to receive “Audi” and then “Saab”.
How can I do this?
That is fundamentally impossible; the browser will always send the values in the order that they appear.
If you want to, you can add Javascript code which tracks the order of selection somewhere else.
However, that would be confusing for the user (most people will not expect selection order to make a difference).
Consider using a different UI.