Return comma separated string as multiple options in select dropdown


I’ve used the select 2 multiple dropdown list to store a comma separated string in the db. example: dropdown list has 1.NONE 2.GREEN 3.YELLOW 4.RED in it. If you select GREEN and YELLOW, it will store in the db as GREEN,YELLOW.

NOW the user needs to be able to edit that so when you get that information back from the db, it only returns GREEN and not the second option being YELLOW.

    $(document).ready(function () { $("#RiskRatingTypes").select2({ multiple: true, placeholder: "Select", allowClear: true}); });

I’ve found the answer.
I’ve returned the entry from the db to the view in a hidden field and added it as an array to the select drop:

    var items = ($('#riskratingfields').val().split(',')); // this is the hidden field which shows as NONE,GREEN
    $(document).ready(function () {
            multiple: true,