0

I want to complete this code step by step to add an image as byte array in an userprofile as profile pic of every user. What I have so far:

[Table("UserProfile")]
public class UserProfile
{
    [Key]
    [DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)]
    public int UserId { get; set; }
    public string UserName { get; set; }
    public byte[] Image { get; set; }
}

Now how to complete code for controler? How to complete code for view? How to complete code for edit view?

Thanks if someone have the time to help me.

bish
  • 3,381
  • 9
  • 48
  • 69

1 Answers1

2

For showing image

@{
    var base64 = Convert.ToBase64String(Model.Image);
    var imgSrc = String.Format("data:image/gif;base64,{0}", base64);
}

<img src="@imgSrc" />

Some Reference for your help :

Upload image included in MVC model

Community
  • 1
  • 1
Kaushik Thanki
  • 3,334
  • 3
  • 23
  • 50