Question How to save Personal Picture on Database Table aspnetUser on mvc .net core 5 ?

ahmedsalah

Active member
Joined
Sep 26, 2018
Messages
32
Programming Experience
3-5
I working on asp.net core 5 mvc web application , I face issue I can't store Picture User on database table [dbo].[AspNetUsers].

so can you tell me how to store personal picture of user on table [dbo].[AspNetUsers].

I already add new column PictureUser on table [dbo].[AspNetUsers] to store User Picture .

I need to know what I will modify on controller and view to store user picture on database table .

I working on Microsoft identity membership when register user

my model as
Model picture user:
public class RegisterVM
{
    public string EmailAddress { get; set; }
    public string Password { get; set; }
    public byte[] PictureUser { get; set; }

}

my action controller
action controller register user:
[HttpPost]
    public async Task<IActionResult> Register(RegisterVM registerVM)
    {
      
        var newUser = new ApplicationUser()
        {
            FullName = registerVM.FullName,
            Email = registerVM.EmailAddress,
            UserName = registerVM.EmailAddress,
            //How to add Image upload Here
        };
    
        var newUserResponse = await _userManager.CreateAsync(newUser, registerVM.Password);
        if (newUserResponse.Succeeded)
        {
            await _signInManager.SignInAsync(newUser, isPersistent: false);
      
            return View("RegisterCompleted");
        }
      
        return View(registerVM);
    }

on view

view html:
@model RegisterVM;


        
                <form asp-action="Register">
                    <div asp-validation-summary="ModelOnly" class="text-danger"></div>

                    
                    <div class="form-group">
                        <label asp-for="EmailAddress" class="control-label"></label>
                        <input asp-for="EmailAddress" class="form-control" />
                        <span asp-validation-for="EmailAddress" class="text-danger"></span>
                    </div>
                    <div class="form-group">
                        <label asp-for="Password" class="control-label"></label>
                        <input asp-for="Password" class="form-control" />
                        <span asp-validation-for="Password" class="text-danger"></span>
                    </div>
                     //How to add Image upload Here

                    <div class="form-group">
                        <input class="btn btn-outline-success float-right" type="submit" value="Sign up" />
                      
                    </div>
                </form>

How to add Image Upload on View And Controller Action this is Exactly my Question ?
 
Solve the upload problem first. You could start with naive file input control in your UI and change that to something more sophisticated that takes drag/drop and provide upload progress later. For now you just want to get the data from the client side into your view model.

Once you have the data in memory (or in a memory stream), then tackle the second problem of putting that data into the MVC identity application user.
 
Back
Top Bottom