Код: Выделить всё
@{
ViewData["Title"] = "Home Page";
}
Welcome to SyncFusion
Click me!
$(document).ready(function () {
$("#btnMe").click(function () {
$.ajax({
type: "POST",
url: "HOME/Users",
data: JSON.stringify({ username: $("#username").val() }),
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (response) {
$(response).each(function (index, item) {
console.log(item);
});
}
});
});
});
Я передал строковое имя пользователя только для целей тестирования и получаю нулевое значение:
Код: Выделить всё
public JsonResult Users(string username){
List Users = new List()
{
new User { Id = 1, Name = "John Doe", Age = 30 },
new User { Id = 2, Name = "Jane Doe", Age = 25 },
new User { Id = 3, Name = "Sammy Doe", Age = 22 }
};
return Json(Users);
}
Код: Выделить всё
public class User
{
public int Id { get; set; }
public required string Name { get; set; }
public int Age { get; set; }
}
Подробнее здесь: https://stackoverflow.com/questions/790 ... controller