Avatar of lulu50
lulu50
Flag for United States of America asked on

show all selected options in Multiselect mvc c# after the submit

Hi,

How can I show all selected items after the submit?

Can someone help me and tell me what I'm doing wrong please?

Model :


        public IEnumerable<SelectListItem> VersionList { get; set; }

        public List<string> SelectedVersion { get; set; }


      public IEnumerable<SelectListItem> GetVersion()
        {
            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(),
                 })
                .Distinct()
                .OrderBy(x => x.Text);
        }

Open in new window




controller: 


 [HttpPost]
  public ActionResult SearchRules(CABRSearchRules model, string[] SelectedVersion)
        {

              model.VersionList = _careAdvanceBusinessRulessService.GetVersion();
            model.SelectedVersion = SelectedVersion.ToList();

      return View(model);
        }

Open in new window




        $('#SelectedVersion').multiselect({
            onInitialized: function (option, checked) {
                var values = [];
                var dropdown = $('#SelectedVersion').siblings('.multiselect-container');
                $('#SelectedVersion option').each(function () {
                    values.push($(this).text());
                });
            },
            enableFiltering: true,
            buttonWidth: '350px',
            maxHeight: 200,
            enableCaseInsensitiveFiltering: true,
        }); 



 @Html.DropDownListFor(m => m.SelectedVersion, new SelectList(Model.VersionList, "Value", "Text"), new { @multiple = "multiple" } )

Open in new window

.NET MVCASP.NET* ASP .NET MVC 5C#

Avatar of undefined
Last Comment
Zvonko

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Zvonko

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
lulu50

ASKER
Zvonko,

Oh my God

I finally got it to work!!!

Thank you for all your help!!

Thank you and Thank you
lulu50

ASKER
Thank you for all your time!!

Thank you so much
Zvonko

I am glad that I could help you  :  )

All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck