1

I'm working with Select2 js(version 4.0.3) with ASP.NET MVC.
I have added reference of js and css files on Layout page.

<script type="text/javascript" src="~/js/select2.min.js"></script>

Here is my view page code where I'm using it.

<div class="col-sm-9">
    @Html.DropDownListFor(m => m.PlatformIds, (MultiSelectList)ViewBag.Platforms, new { @class = "form-control select2", @multiple = true })
</div>

For instance, platforms having data like Vitro, Nop and Woo. When user select any option, it sort in alphabetical order by default.

How can we stop that alphabetical order?

I have seen same issue over here: In multi-select, selections do not appear in the order in which they were selected But don't know where to fix, as I'm using min js file.

Hina Khuman
  • 757
  • 3
  • 14
  • 41
  • Not related, but you need to use `ListBoxFor()` for correct binding - refer [this answer](https://stackoverflow.com/questions/40725358/why-does-the-dropdownlistfor-lose-the-multiple-selection-after-submit-but-the-li/40732481#40732481) –  Jun 12 '18 at 06:36
  • A ` –  Jun 12 '18 at 06:39
  • And what I need to do if I want in order selected by user? – Hina Khuman Jun 12 '18 at 06:52
  • try this link - https://github.com/select2/select2/issues/3106 – Sahil Sharma Jun 12 '18 at 07:04
  • @SahilSharma: Thanks but I think you should see all the things mentioned in the question. – Hina Khuman Jun 12 '18 at 07:13
  • @Hina Khuman - The default ordering of selection items is a feature of select2. This link I have referred you to is a bug opened about the same. Try to go through the answers, there are few workarounds mentioned. – Sahil Sharma Jun 12 '18 at 07:15
  • @SahilSharma: I have gone through that thread already as I mentioned in the question with pinned this thread link, yes there are workarounds it, but seems not appropriate with my case. That's why I asked it here. – Hina Khuman Jun 12 '18 at 07:25

0 Answers0