TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Guest User
Tech Writer
611
127.9k
MultipartForm Data in .net core.
Jul 21 2020 2:40 AM
[HttpPost]
[Route("UpdateProfile")]
[Consumes("multipart/form-data")]
public async Task<UpdateProfileResult> UpdateProfile([FromForm]UserProfile Profile)
{
UpdateProfileResult obj_result = new UpdateProfileResult();
UserProfile obj_deatil = new UserProfile();
try
{
var check_user = _context.UserMaster.Where(x => x.UserId == Convert.ToInt32(Profile.UserId)).FirstOrDefault();
if (check_user != null)
{
obj_deatil.UserId =Convert.ToString(check_user.UserId);
var user = _context.UserProfileMaster.Where(x => x.UserId ==Convert.ToInt32(Profile.UserId)).FirstOrDefault();
if (user != null)
{
user.UserId =Convert.ToInt32(Profile.UserId);
user.FirstName = Profile.UserName.Contains("") ? Profile.UserName.Split(" ")[0] : Profile.UserName;
user.Address = Profile.Address;
user.MobileNumber = Profile.MobileNumber;
user.Country = Profile.Country;
user.LevelBaseBall = Profile.LevelBaseBall;
user.ZipCode = Profile.ZipCode;
user.InstaUserName = Profile.InstaUserName;
string filePath = null;
var wwwrootPath = webHost.ContentRootPath + "\\uploads\\";
string thisFileName = Path.Combine(Profile.UserImage.FileName);
if (Profile.UserImage?.Length > 0)
{
filePath = Path.Combine(wwwrootPath, Profile.UserImage.FileName);
using FileStream fileStream = new FileStream(filePath, FileMode.Create);
await Profile.UserImage.CopyToAsync(fileStream);
}
user.UserImage = thisFileName;
user.UpdateDate = DateTime.UtcNow;
_context.SaveChanges();
it's me updated code .I have send json in multipart form Date .It's run on local server but this code not run in Live server .
Throwing error -internal server error.
public class UserProfile
{
public string UserId { get; set; }
public string UserName { get; set; }
public string MobileNumber { get; set; }
public string Country { get; set; }
public string LevelBaseBall { get; set; }
public string ZipCode { get; set; }
public string UpdateDate { get; set; }
public string InstaUserName { get; set; }
public string Address { get; set; }
[Column(TypeName = "date")]
public string DOB { get; set; }
[Required]
public IFormFile UserImage { get; set; }
}
Please check this.
Reply
Answers (
2
)
How to assign icon to Tree View nodes...?
Reset Link on mail .net core.