0
asp.netアプリケーションで新規ユーザーを登録したいと思います。フォームを使用する代わりに、私はAjaxを使いたいと思います。フォームなしでasp.netアプリケーションで新規ユーザーを登録する
これは私のAccountControllerで私のポスト機能である:
[System.Web.Mvc.HttpPost]
public async Task<bool> Register(UserItem post) {
try {
var user = new ApplicationUser { UserName = post.UserName, Email = post.UserName };
var result = await UserManager.CreateAsync(user, post.Password);
if (result.Succeeded) {
post.Id = user.Id;
await _userRepository.Save(post);
return true;
}
AddErrors(result);
}
catch (Exception e) {
Console.WriteLine(e);
}
// If we got this far, something failed, redisplay form
return false;
}
そして、これは私のコントローラに私のAjax呼び出しです:
var userJson = ko.toJSON(self.selectedUser);
console.log(userJson);
$.ajax({
type: "POST",
url: "http://localhost:7061/Account/Register",
headers: "application/json; charset=UTF-8",
dataType: "json",
contentType: "application/json",
data: userJson,
error: function (xmlHttpRequest, textStatus, errorThrown, response) {
},
success: function (response) {
console.log(response);
self.loadUsers();
}
});
しかし、コントローラの私のレジスタ関数が呼び出されることは決してありません。
ありがとうございました。
返します。ブラウザで –
F12を押し、「ネットワーク」をチェックして、返された結果を確認します。エラーを見つけるのに役立ちます。あなたはデータを試しましたか:{post:userJson}、 – KevDevMan
なぜ '仕事<>'でboolを使うのですか? –