I have created a web application using ASP.NET MVC. Basically I have an user input form, which includes an HTML table. The user can add new rows to the table if needed. How do I determine, how many rows there are and how do I post them back to the controller?
Asked
Active
Viewed 387 times
-2
-
Refer [POST a form array without successful](http://stackoverflow.com/questions/29161481/post-a-form-array-without-successful/29161796#29161796) – Oct 12 '16 at 22:35
3 Answers
0
Count the length of a certain class could work. So at each row you put like class="count-me" then you could just get the length of "count-me" with javascript!

xatroN
- 88
- 11
0
If you use jquery you can use the selector $(table tr).length to count the number of rows.

Rémy
- 736
- 1
- 5
- 19
0
You may use javascript for counting row number and send that with a hidden input field
javascript for row count:
var rows = document.getElementById(tableId).getElementsByTagName("tr").length;

Safwan Rizvi
- 46
- 3
-
if u didnt have specific Id for table. you may use getElementsByTagName("TABLE")[0] instead of getElementById(tableId) – Safwan Rizvi Oct 12 '16 at 14:32