views:

51

answers:

1

Hello,

I have a problem to get a value of textbox which is in view into the controller.

In WebForms it was quite easy, it needed just to call textbox in codebehind trouhg Id, but in MVC it seems not possible this way, or?

Help me please!

Take care, Ragims

+4  A: 

Hey,

You need to post the form data back to the controller... when this happens, it attempts to map a property value handling the action method and auto assign it. So if you have:

<input type="text" id="T1" name="T1" />

In a form post, it will post to action method:

public ActionResult Process(string T1)

Or you can use a FormCollection instead

public ActionResult Process(FormCollection form)

Which contains all of the values posted back.

But you have to post back, either via a form and clicking a submit button (only what's in the form gets posted) or by using a JS library to post the form (like JQuery).

Brian
+1 They could also use Request.Form["T1"]. Just thought I'd ad that.
XstreamINsanity
thank you brian, you helped me to find right direction to solve my problem. great help from you, thanks again!
Ragims