-1

I have an MVC5 application, and in one of my view I have something like this:

<textarea id="msg" rows="5" cols="90"></textarea> <br />
@Html.ActionLink("Submit Message", "WriteMessage", new { message = msg }) <br />

The point is that, I want to get the value, meaning the text written inside my textarea with the id of msg, and pass that as object routeValue during my ActionLink. The above code doesn't seem to work. How can I achieve that?

In case you wonder, my WriteMessage method is defined like this:

public ActionResult WriteMessage(string message)
tett
  • 595
  • 3
  • 13
  • 34
  • This very much appears to be an [XY Problem](http://meta.stackexchange.com/a/66378/171858). You haven't given any reason why these requirements are necessary, nor why a standard form POST with a method with the same signature you are using that would do model binding automatically won't work for you. – Erik Philips Dec 18 '14 at 16:16

1 Answers1

1

The way you are trying to do this will never work. The Html.ActionLink is code that runs on your server, which means it runs long before your user ever sees the textbox, let alone fills it in. You could put it in a form and put a name attribute on the textbox and that should work.

@using(Html.BeginForm("WriteMessage", "Your Controller Name", FormMethod.Get))
{
    <textarea id="msg" rows="5" cols="90" name="message"></textarea>
    <br/>
    <input type="submit" value="Submit Message"/>
}
Becuzz
  • 6,846
  • 26
  • 39