lulu50
asked on
reselect Multiselect option
Hi,
I'm creating a search page
1. on the page there is a multiselect dropdown list
2. I select some options from the list
3. I click on the submit button
4. after submitting the page my selection will get cleared out
How can I get my selection back once I click on the submit button?
I'm creating a search page
1. on the page there is a multiselect dropdown list
2. I select some options from the list
3. I click on the submit button
4. after submitting the page my selection will get cleared out
How can I get my selection back once I click on the submit button?
$('#SelectedVersion').multiselect({
onInitialized: function (option, checked) {
var dropdown = $('#SelectedVersion').siblings('.multiselect-container');
//Here I want to reselect the options that I have already selected after submitting my form
onInitialized: function (option, checked) {
var values = [];
var $SelectedOptions = $(this).find('option:selected');
$SelectedOptions.each(function () {
values.push($(this).text());
});
},
enableFiltering: true,
buttonWidth: '350px',
maxHeight: 200,
enableCaseInsensitiveFiltering: true,
});
<td>
@Html.DropDownListFor(m => m.SelectedVersion, new SelectList(Model.VersionList, "Value", "Text"), new { @multiple = "multiple" } )
</td>
ASKER
Zvonko,
Thank you for responding to my question
yes the server is handling the selected return values.
they are in the SelectedVersion
@Html.DropDownListFor(m => m.SelectedVersion, new SelectList(Model.VersionLi st, "Value", "Text"), new { @multiple = "multiple" } )
Thank you for responding to my question
yes the server is handling the selected return values.
they are in the SelectedVersion
@Html.DropDownListFor(m => m.SelectedVersion, new SelectList(Model.VersionLi
ASKER
public IEnumerable<SelectListItem> GetSelectedVersion(string[] SelectedVersions)
{
var GetVersion = _unitOfWorkCABusinessRules.RuleDetailRepo.GetAll().GroupBy(x => x.Version).Select(y => y.First()).Distinct();
return GetVersion
.Select(x => new SelectListItem
{
Text = x.Version,
Value = x.Version.ToString(),
Selected = //here how can I say to select the ones in the SelectedVersions ?
})
.Distinct()
.OrderBy(x => x.Text);
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Everything for keeping multi selecteion states selected by user is already done by the @Html.DropDownListFor helper.
All additional code is only disturbing the helping states.
ASKER
Thank you for all your help!!
it's working now
it's working now
The page after submit is not cleared but fresh loaded and has no access to previous variables or page control states.
Therefore you need some options selcted information either from server or from stored cookies.
Can you send the options selected state from server after submit?