hello there is a request

function update(value) { $.ajax({ url: "/Home/Test", type: "POST", data: value, success: function (data) { $("#data").text(data); } }) } 

Controller

 public ActionResult Test(string value) { return View(value); } 

Visually, nothing happens, but in the Chrome inspector it says that the server responded with an error 500 Internal Server Error

The request happens when you type in input

 @using (Ajax.BeginForm(new AjaxOptions { })) { @Html.TextBox("list", null, new { @class = "sort", @oninput = "update(this.value)", @parametr = "this.value" }); } 

UPDATE Changed method type to string

 public string Test(string value) { return value; } 

Like the value returns and it is written in a div but it is not displayed on the page.

    1 answer 1

    The parameter in the controller method is called value . The binding of parameters to the request data occurs by the parameter names / data keys of the request. For this to work (without additional actions), the key names must match.

    But the error on the server, most likely, was caused by the lack of a View (view) Test or an error inside it ( return View(value); ).

     function update(aValue) { $.ajax({ url: "/Home/Test", type: "POST", data: {value: aValue}, // !!! success: function (data) { console.log("In success:"); console.log(data); $("#data").text(data); }, error: function(jqXHR, textStatus, errorThrown) { console.log("In error: " + textStatus + " - " + errorThrown); console.log(jqXHR); } }) } 
    • Thank you very much. And why exactly value : value - Sasuke
    • @ Sanitary The parameter in the controller method is called value . The binding of parameters to the request data occurs by the parameter names / data keys of the request. For this to work (without additional actions), the key names must be the same. - Igor