[RESOLVED]Checkbox elements not in formCollection

I have a form with a variable number of selectors and checkboxes – each selector checkbox pair contained in a separate div.  When I submit these values to the controller, only the selector elements are represented in the formCollection object – the checkboxes
are not there.

Here’s the html on the form:

<form action="/FeatureDetails/UpdateRelatedFeatures" method="post">

    <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="SEL_8590b777-47ea-4298-8e83-43d584f54323" name="SEL_8590b777-47ea-4298-8e83-43d584f54323" style="max-width: 200px;">
			<option value="D">option 1</option>
			<option value="H">Option 2
		<input id="CHK_8590b777-47ea-4298-8e83-43d584f54323" type="checkbox">Remove</input>
	</Div>
	<Div>
		<select id="SEL_3c3e47d6-ebf5-421e-aa21-54618b5d8745" name="SEL_3c3e47d6-ebf5-421e-aa21-54618b5d8745" style="max-width: 200px;">
			<option value="D">option 1</option>
			<option value="H">Option 2
		</select>
		<input id="CHK_3c3e47d6-ebf5-421e-aa21-54618b5d8745" type="checkbox">Remove</input>
	</Div>            
	<button type="submit">Submit</button>

</form>

And here’s the code from the controller:

        public void UpdateRelatedFeatures(Guid FeatureID, Guid LayerID, FormCollection UpdateValues) { 

            List<NewRelatedFeature> RelatedList = new List<NewRelatedFeature>();

            foreach (string PostBackKey in UpdateValues.AllKeys) {
                if (PostBackKey.ToUpper() != "FEATUREID" && PostBackKey.ToUpper() != "LAYERID") { 
                    AddFeatureToList(RelatedList, PostBackKey, UpdateValues);
                }
            }

        }

Can anybody see what I’m doing wrong?

Hi,

If a field doesn’t have a name attribute, it is not posted to the server. Try to add a name attribute on your checkboxes.

dolot

<option value="H">Option 2

close tag not exists


dolot

<select id="SEL_8590b777-47ea-4298-8e83-43d584f54323" name="SEL_8590b777-47ea-4298-8e83-43d584f54323" style="max-width: 200px;">
			<option value="D">option 1</option>
			<option value="H">Option 2

close tag not exists for select tag


dolot

<option value="H">Option 2

same close tag

But all of those not the reason for checkboxes not being posted. check boxes not having name attribute


dolot

<input id="CHK_3c3e47d6-ebf5-421e-aa21-54618b5d8745" type="checkbox">Remove</input>

 

<input id="CHK_3c3e47d6-ebf5-421e-aa21-54618b5d8745" name="chk2" type="checkbox">Remove</input>

Thanks, Patrice – that fixed it.  I always thought the id attribute was the critical one.  Now I know better.

Leave a Reply