0

I have a table that is dynamically created using JQuery. I need to pass the IDs of every row in that table to the controller so that I can save the values to the Database. My HTML for the dynamically created rows looks like this

<td class="text-center" style="width:100px;" name="RegistrationTypeInspectionType.InspectionTypes" value="5">
    <button class="removeInspectionType" type="button" data-val="5">Remove</button>
</td>

here is a code snippet of what my C# looks like

var registrationTypeInspectionTypes =
                 new BusinessLayer.RegistrationTypeInspectionType().GetAll();

model.RegistrationTypeInspectionType.RegistrationTypeInspectionTypes =
                                                     registrationTypeInspectionTypes;

when I submit the form these values are not being sent to the controller.

1 Answer 1

2

Only input fields are submitted not the td or tr of the table. Please try to create hidden fields in each td with the name you want to submit. your table should look like this

<td class="text-center" style="width:100px;" name="RegistrationTypeInspectionType.InspectionTypes" value="5">
<input type="hidden" name="RegistrationTypeInspectionType.InspectionTypes" value="5"/>
<button class="removeInspectionType" type="button" data-val="5">Remove</button>

Now when you submit the form these hidden fields will also be submitted and you can get these in the controller.

Sign up to request clarification or add additional context in comments.

3 Comments

i literally just found an article that was similar to what you posted. I am about to try this now... i have a feeling it is going to work. I'll update in a bit
that's great if it is helpful to you.
thank you for your help! this worked. now i just need to fix the rest of my code lol.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.