asp.net core 2.2
model.file or another file.Don't come file.Everytime is null. Nested ajax or running order ajax.
I want to update profile. I was able. When the file upload into the work, I exploded.
File upload and user update with different ajax queries? Should I expect different ajax queries in different methods? or is it handled in a single ajax query?
Sorry, my bad english.
Controller:
public IActionResult UpdateProfile(ProfileModel model, IFormFile file)
{
var result = userOperation.UpdateUser(model).Result;
if (result.Succeeded)
{
return Ok();
}
else
{
return BadRequest();
}
}
ProfileModel:
public class ProfileModel
{
public string UserId { get; set; }
public string username { get; set; }
public string Name { get; set; }
public string SurName { get; set; }
public string ProfilePhoto { get; set; }
public IFormFile file { get; set; }
}
Jquery:
var isim = $('#name');
var soyisim = $('#surname');
var menu = $('#navInside');
var cikis = $('#logout');
var updateCikis = $('#exit');
var update = $('#update');
var goUpdate = $('#goUpdate');
var kaydet = $('#kaydet');
var dosya = $('input[type=file]');
var username2 = $('#username').val();
kaydet.click(function (event) {
event.preventDefault();
$.ajax({
url: '/Registered/UpdateProfile',
data: { Name: isim.val(), SurName: soyisim.val(), username: '@User.Identity.Name' },
type: 'POST',
success: function (result) {
console.log('basarili güncelleme');
var formData = new FormData();
formData.append('file', dosya[0].files[0].name);
console.log(dosya[0].files[0].name);
console.log(JSON.stringify(dosya[0].files[0]));
$.ajax({
url: '/Registered/UpdateProfile',
data: { Name: isim.val(), SurName: soyisim.val(), username: '@User.Identity.Name', file: formData },
processData: false,
contentType: false,
type: 'POST',
success: function(){
alert('foto da gittiii');
}
});
}
});