Click here to Skip to main content
15,921,697 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
i have a profile picture which appear on my page. Now i want user to be able to change their default profile picture by click on it. How can i achive this this here is my code

<
HTML
<a class="media-left pr-n" href="">
                    <img class="media-object img-resposnive" src="@Model.ImageStore.GetPublicImageUrl()" alt="Generic placeholder image" width='88' height='88'>
                </a>


What I have tried:


<img class="media-object img-resposnive" src="@Model.ImageStore.GetPublicImageUrl()" alt="Generic placeholder image" width='88' height='88'>
Posted
Updated 26-Jul-16 5:33am
Comments
ZurdoDev 26-Jul-16 7:34am    
Put an onclick event on the img and then write code to do it. Where are you stuck?

You would need to code the logic for changing the profile picture. The idea is to wireup a JavaScript click event and then have the user choose a picture. You can then issue an AJAX request to store the uploaded file to your server for future use. And finally, set the src of your image to the new uploaded image.

I believe there are tons of examples that demonstrate how to do it in jQuery. It's either using a plugin or rolling your own code to do the uploading. Just find them at google.
 
Share this answer
 
use jquery to select the element and create a onclick event. The easiest way to do this is to use an ID.

add an id to the img tag of say "profile_pic".

then in your javascript file do.

JavaScript
$('#profile_pic').on('click', changePic);


then have a function called changePic to do the changing logic, i.e load up a dialog with a file upload input etc.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900