Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET MVC Razor
Hi,
 
Now i am really confused about formcollection in MVC3. I add HTML table ,named "idxtbl", in my view page. Then i populated with 5 rows. How should i get all the rows when page is post back ?
 
Private ActionResult GetRow(Formcollection frmcol){
          //How should i get all the rows in HTML table from GetRow View Page.
}
Thanks,
frog
Posted 9-Jul-12 15:47pm
Comments
Karthik. A at 9-Jul-12 21:52pm
   
Only a form field (like textbox, textare etc) will be posed back using a formcollection. And MVC supports automatic model binding.
 
// txtName is a text box in the form
public ActionResult Index(string txtName)
{
return View();
}
 
A table is just html and that WON'T be posted back in a formcollection.
Karthik. A at 9-Jul-12 21:55pm
   
What is your requirement exactly? I cannot think of a reason you would want to do this. If you could elaborate, one of us could help!
dartfrog at 10-Jul-12 0:15am
   
Hi Karthik, Thanks for your reply. Actually, there are two text boxes and Two buttons in view page. user need to key in two text boxes first and then press the button so all the records that user key in will be added inside HTML table(Using JQuery). When user populated with rows in HTML table, need to press another button(will trigger to GetRow action) to save all the records within the database.
Karthik. A at 10-Jul-12 10:59am
   
Can't you save the data user enters in to the database already using $.ajax and then just append this row to the table? Because in order to send an entire table, you may have to maintain a whole lot of hidden fields. I would do something like this:
 
1. Have a url /home/add/ which gets 2 values
2. Call it using jQuery's $.ajax passing the value of these 2 text boxes
3. The "Add" method would return json indicating the result of add
4. Then use jquery again to add it to the table.
5. By this way you eliminate the 2nd button altogether.
6. Then when you are re-displaying the page, you pass the values in the db as the model
 
Hope this helps!
dartfrog at 10-Jul-12 22:31pm
   
Ok Thanks, currently i tried with one hidden textbox. i store all the values in this hidden textbox such as 'Val1-Val2|Val3-Val4|Val5-Val6'
I'll try with your way also.
 
Thanks for your reply.

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

You might try binding a collection to the data in your table, but I suspect strongly that you'll be iterating over the form data to find and parse it yourself. There are some frameworks for MVC3 and tables, perhaps they will help ( no, I've not used one )
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Nirav Prabtani 268
1 OriginalGriff 217
2 Mika Wendelius 185
3 _Amy 170
4 CPallini 170
0 Nirav Prabtani 284
1 OriginalGriff 217
2 Mika Wendelius 185
3 _Amy 170
4 CPallini 170


Advertise | Privacy | Mobile
Web02 | 2.8.140721.1 | Last Updated 14 Aug 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100