I want to send the email (string) from aspnet/identity to my dbcontext on registration. The console outputs
Failed to load resource. the server responded with a status of 415 () :5001/api/UserEntities/insertEmail:1
When I click on the part in italics I get:
{"type":"https://tools.ietf.org/html/rfc7231#section-6.5.13","title":"Unsupported Media Type","status":415,"traceId":"00-30216fe89ca6b54e8fa1121b1954ad81-0a607d94a5b71142-00"}
RegisterConfirmation.cshtml
var data = {
email: $('#email').val()
};
$(document).ready(function () {
$.ajax({
type: "POST",
url: '../../api/UserEntities/insertEmail',
data: data,
success: function () {
alert($('#email').val()); //this shows the email correctly in the popup
}
});
});
UserEntitiesController.cs
[Route("insertEmail")]
public void Insert([FromBody] string email)
{
_uecontext.Users.Add(new DinderDL.Models.UserEntity
{
Email = email
});
_uecontext.SaveChanges();
}
I have also tried this with the same result:
$(document).ready(function () {
$.post('../../api/UserEntities/insertEmail', {
email: $('#email').val();
}).then(alert('hello'));
});
except I get:
POST https://localhost:5001/api/UserEntities/insertEmail 415
send @ jquery.min.js:2
ajax @ jquery.min.js:2
S.<computed> @ jquery.min.js:2
(anonymous) @ RegisterConfirmation?email=baba@gmail.com&returnUrl=%2F:71
e @ jquery.min.js:2
t @ jquery.min.js:2
setTimeout (async)
(anonymous) @ jquery.min.js:2
c @ jquery.min.js:2
fireWith @ jquery.min.js:2
fire @ jquery.min.js:2
c @ jquery.min.js:2
fireWith @ jquery.min.js:2
ready @ jquery.min.js:2
B @ jquery.min.js:2