troubleshooting Question

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

Avatar of lulu50
lulu50Flag for United States of America asked on
.NET MVCASP.NET* ASP .NET MVC 5C#
4 Comments1 Solution117 ViewsLast Modified:
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);
        }



controller: 


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

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

      return View(model);
        }



        $('#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" } )
ASKER CERTIFIED SOLUTION
Zvonko
Systems architect
Join our community to see this answer!
Unlock 1 Answer and 4 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 4 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros