There is a method in the controller:
[HttpPost] [ValidateAntiForgeryToken] //public async Task<Users> Post([FromBody] Users user) - тоже пробовал public async Task<Users> Post([Bind(Include = "id,FIO,login,password,date_for_last_sign_in")] Users user) { return user; } model:
using System; using System.Collections.Generic; using System.Linq; using System.Web; namespace WebApplication2.Models { public class Users { public int id { get; set; } public string FIO { get; set; } public string login { get; set; } public string password { get; set; } public DateTime date_for_last_sign_in { get; set; } } } Question: how to check the functionality of the function?
I created a button and try this:
$(document).ready(function () { $("#addUser").click(function () { var users = { id: 1, FIO: "fio", login: "log", password: "pass", date_for_last_sign_in: "2012-04-23T18:25:43" }; $.ajax({ url: '/api/values/', type: 'POST', data: JSON.stringify(users), contentType: "application/json;charset=utf-8", success: function (data) { alert(data); }, error: function () { alert("error");} }); }); }); I get an empty object, why so?
error: function () { console.log(this); }error: function () { console.log(this); }-? - Igorajax usersremove[ ]? Or how can I send the object? As far as I know, if the JSON array corresponds to an object, from MVC the object itself is riveted from it. But for some reason this does not happen. Perhaps with the type of error? But with what? - Vitali Shebanits