Mohammad Dayyan
Mohammad Dayyan

Reputation: 22408

Get all textboxes' values in a form in MVC3?

I have a form tha contains a TreeView with many Textboxes in each node. the TreeView created dynamically with Razor and I don't know the name or ID of textboxes.
How can I get the value and id of all textboxes in the controller in MVC3 ?

Upvotes: 0

Views: 1287

Answers (2)

Tim B James
Tim B James

Reputation: 20364

I would use the FormCollection class. Read about it here http://msdn.microsoft.com/en-us/library/system.web.mvc.formcollection.aspx

In your controller;

Public ActionResult ActionName(FormCollection formCollection){
}

This allows you to gain access to any of the keys posted.

Upvotes: 6

Rob Rodi
Rob Rodi

Reputation: 3494

Request.Form.AllKeys will allow you to access all the fields in the form's ids. Then you can use Request.Form[id] to access the value.

Edit: Possible Dupe:How can I get all element values from Request.Form without specifying exactly which one with .GetValues(“ElementIdName”)

Upvotes: 2

Related Questions