how to add image as byte[] in userprofile and then upload and display it in mvc4

943 views Asked by At

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.

1

There are 1 answers

0
Kaushik Thanki On BEST ANSWER

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