ASP.NET MVC - how to get value from text field in my view?

If I have a text box in my view:

<div><%= Html.TextBox("Comments", Model.Comments)%></div>

I want to publish the contents of this text box to the controller using an Ajax call. I need only one value, so I do not want to publish the whole form.

<%= Ajax.ActionLink("update", "UpdateComments", 
                new { comments = /* ????? */ }, 
                new AjaxOptions { HttpMethod="POST" })%>

How to get the value of a text field?

+3
source share
4 answers

Ajax.ActionLink - , JS , AJAX. , , , . HTML JS, , ( , ).

+1

, - , Ajax (, jQuery), .

+2

jQuery .

$("#Comments").val();
+2

Ajax jquery.

  function FunctionName() {
        $.Post(URl, function(data) {

        });
    }
0

Source: https://habr.com/ru/post/1749923/


All Articles