I have a select2 drop down and I want to select default values for the list items. It works fine when I use hard code values for setting the default values of the dropdown like this
$('#PlatFormTitle').val(['1','2','3']);
But I want to select values based on the data obtained from the model. Here is the code I am trying can someone please identify what am I doing wrong here.
var PlateForms = [];
var x;
@foreach(var PlateForm in Model.UserPlateFormList)
{
@:x = '@PlateForm';
@:PlateForms.push(x);
}
$('#PlatFormTitle').val(PlateForms);
$('#PlatFormTitle').trigger('change');
I tried this as well.
$('#PlatFormTitle').val(JSON.stringify(PlateForms));
$('#PlatFormTitle').trigger('change');
