[RESOLVED]Having issues posting values from a multiselect Selector

I have the following form on a page:

<form action="/FeatureDetails/UpdateRelatedList">
        <input data-val="true" data-val-required="The FeatureId field is required." id="FeatureID" name="FeatureID" type="hidden" value="1058dd12-5a06-48e5-9cfc-7918db27cbe7" />
        <input data-val="true" data-val-required="The LayerId field is required." id="LayerID" name="LayerID" type="hidden" value="68d05b3e-ddeb-4d45-ab25-21e869ec10e3" />
        <div>
            <select id="FeatureSelectionList" multiple="multiple" name="FeatureSelectionList" size="7" style="max-width: 600px;"><option value="08b831bc-b9db-483e-a0c0-20a1240c6b28">Barricade - </option><option value="8590b777-47ea-4298-8e83-43d584f54323">Building 1 - </option><option value="3c3e47d6-ebf5-421e-aa21-54618b5d8745">Building 4 - </option><option value="de06b65d-68c3-46cf-a0c2-6c89c9d9a2bc">Building 3 - </option><option value="87f10db5-9c81-4a57-b267-899ce489ac4c">Magazine - </option><option value="69fa989d-c323-4c14-9ac3-acdf3e75f4bc">Building 2 - </option></select>
        </div>
        <button type="submit">Update List</button>
    </form>

And here is the controller action that receives the postback:

public ActionResult UpdateRelatedList(Guid FeatureID, Guid LayerID, FormCollection collection) 
        {
            foreach (string KeyPostBack in collection.AllKeys) {
                // nothing here
            }
            return View();
        }

The FeatureID and LayerID come through just fine – being populated from the hidden inputs on the form, but there’s nothing there for the selector’s selections.  I’ve tried selecting more than one item, but nothing gets posted back.

Have I chosen the wrong architecture? 

 

Here is a link that  I believe will help you with what you are doing: http://dotnetvisio.blogspot.ca/2014/01/get-values-of-multiselect-listbox-in.html

What you can do is change the type of the last parameter of your action to IEnumerable<string> and also rename it to FeatureSelectionList (matches ID/Name).

Yep, putting the iEnumberable<string> with the matching name did the trick.  Thanks!

But now I wonder… I have another controller function that accepts the formCollection from another form and it has selectors in it.  However, they aren’t multiselect lists – just regular dropdown selectors, so maybe that’s the difference.

Thanks again!

Leave a Reply