1

I made a textarea where I want people to be able to enter a comment. I then have a method in a controller that is supposed to use that string.

How do I pull the information from the textarea into the method?

2
  • How do you reach that method? When handling a POST request? Commented Oct 31, 2012 at 13:01
  • MVC does not work the same as webforms, where you can pull the value out of the textarea from the codebehind. Marios answer below is how you need to do this. Commented Oct 31, 2012 at 14:32

1 Answer 1

3

I don't know how your View or Action method looks like, but give your TextArea a name, like comment:

@using (Html.BeginForm("MyAction", "MyController")) {
    @Html.TextArea("comment")

    <input type="submit" value="Submit" />
}

And then make sure you have a parameter in your action with the same name:

[HttpPost]
public ActionResult MyAction(string comment)
{
    // Do something with the comment
}

When you post, the default model binders will take care of putting the text from your TextArea into the comment parameter.

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

Comments

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.