How to update image with JavaScript and ASP.NET MVC?

DmitryBoyko

I use ShowImage() method of the Home controller to show the image generated on fly.

HTML

<img src='@Url.Action("ShowImage", "Home" )' width="267" height="500">

Now I would like to execute some action with AJAX and update that image like this

 $.ajax({
     type: "POST",
     url: '@Url.Action("UpdateUser", "Home")',
     contentType: "application/json; charset=utf-8",
     data: JSON.stringify(params),
     dataType: "json",
     success: function (data) {
         if (data.success.toString() == 'true') {

             // Is it possible update image using JavaScript?


         }
     }
 });

Is it possible to do? Thanks!

Adriien M

Your controller can return an Image with the base File method:

public ActionResult Image(string id)
{
     var myStream = new byte[0];
     // your code géneration....
     return File(myStream, "image/jpeg");
}

Than, you change the image src attribute:

$("#image").attr("src", "/MyController/Image/2");

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to Update Model in ASP NET MVC 6?

From Dev

How to update database with ajax/javascript without refreshing page asp.net mvc

From Dev

How can I use JavaScript to show or hide an image in MVC ASP.NET?

From Dev

javascript or ajax to update database with asp.net mvc?

From Dev

Update a record in ASP .Net MVC

From Dev

Update a record in ASP .Net MVC

From Dev

How to update asp net webforms or mvc application without losing session?

From Dev

How to update table in ASP.NET MVC 5 Razor Database

From Dev

How to get old entity value on update in ASP.NET MVC

From Dev

How to display saved image in a folder in ASP.net MVC

From Dev

How to upload a Image in Asp.net MVC using Ajax request

From Dev

How to set the background image in asp.net mvc4

From Dev

How to display saved image in a folder in ASP.net MVC

From Dev

How to append key to an image's name asp.net mvc

From Dev

How to store an Image URL in database and use it in ASP.NET MVC?

From Dev

How to delete the old image in ASP.Net MVC

From Dev

How to pass javascript data to controller ASP.NET MVC

From Dev

ASP.NET MVC how to change less variables with javascript?

From Dev

How to get a value from View to JavaScript in asp.net MVC

From Dev

Javascript onload MVC ASP .NET MVC

From Dev

Unable to update cookies in asp.net mvc

From Dev

Asp.net MVC image caching in browser

From Dev

Image upload to tinymce for asp.net mvc

From Dev

ASP.net MVC Image Routing

From Dev

Passing Image to Controller ASP.NET MVC

From Dev

Capture image by Webcam in Asp.Net MVC

From Dev

Asp.net MVC image caching in browser

From Dev

Display uploaded image asp.net mvc

From Dev

ASP.NET MVC not displaying image

Related Related

HotTag

Archive