0

I have a textarea something like this:

<textarea id="textreview" name="textreview"></textarea>

On the click of a button, I need this pass this information to a controller action defined inside the controller.

<button onclick="sendReview()"></button>

The jquery sendReview() function looks like this:

<script>
    function sendReview() {
        var textreview = $('#textreview').val();
        window.location.href = '@Url.Action("ControllerAction", "ControllerName", new { review = textreview })'
    }
</script>

However, unfortunately I get an error:

The name textreview does not exist in the current content

How can I send the parameter to the controller action?

Thanks for the help. Much appreciated.

Rory McCrossan
  • 331,213
  • 40
  • 305
  • 339
  • You can't. I'd suggest you research the difference between client side and server side code. To do what you require you would need to use AJAX. – Rory McCrossan Nov 22 '16 at 11:10
  • `window.location.href = '@Url.Action("ControllerAction", "ControllerName")' + '?review=' + textreview;` But you should be using form with `FormMethod.Get` –  Nov 22 '16 at 11:11
  • You can use it like `window.location.href = '@Url.Action("ControllerAction", "ControllerName")' + '?review=' + textreview`. However better option should be to Post form – Satpal Nov 22 '16 at 11:12
  • Thanks a lot for the help. After so much struggle and SOing, I am considering shifting over to Ajax finally. – Aditya Agarwal Nov 22 '16 at 11:19

0 Answers0