Reputation: 2411
I have Viev with textarea:
<textarea name="textareamessage" rows="10" cols="100" class="form-control" id="message" required data-validation-required-message="Please enter your message" maxlength="999" style="resize:none"></textarea>
and I whant to pass value of that textarea to my controler by method:
public void SendMessage(string messsage)
{
...
}
so what I nead to have after message =
in:
<button type="submit" class="btn btn-primary" onclick="@Html.Action("SendMessage", new {messsage = })">Send message</button>
(button is in this same cshtml that textarea ) to sen value of that textarea?
Upvotes: 0
Views: 1068
Reputation: 239350
First, you're using Html.Action
which causes a child action to be rendered where it's called. It looks like you're looking for Url.Action
or Html.ActionLink
.
Second, that code is not even correct. The value of onclick
must be some JavaScript expression. All you're passing is just a URL, which without quotes, is not even valid JavaScript. If you did add quotes, then it's just a JavaScript string, which won't do anything on its own.
Third, I'm not sure why you're even doing it that way, as your button here is a submit button, so assuming both this button and the field is wrapped in the same form
element, then it works out of the box - no need for onclick
or any JavaScript at all.
Finally, it seems you don't understand how client-server works. Razor (your @Html.Action
) is processed server-side, while the field's value won't be set by the user until it's already been rendered by the server and sent to the client (the web browser) as a response. Therefore, there's no way to access the user's input before the user has even seen the form, let alone input anything.
Upvotes: 2