I have a button sending an input from a text field in a form to my mvc controller using ajax. I now want the controller to return 2 strings as a json, and fill those strings into html inputs.
Controller
[HttpPost]
public ActionResult getName(string Name)
{
string SecondString = "secondString";
return Json(Name, SecondString);
}
View
<script>
$(document).ready(function () {
$("#btnGet").click(function () {
$.ajax(
{
type: "POST",
url: "home/getName",
data: {
Name: $("#txtName").val()
},
success: function (result) {
$('#FirstTextFieldToFill').val(result);
$('#SecondTextFieldToFill').val(result);
},
failure: function (response) {
alert(response.responseText);
},
error: function (response) {
alert(response.responseText);
}
});
});
});