Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8155745
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T16:45:15+00:00 2026-06-06T16:45:15+00:00

Controller to get an image: public class PicturesSmallController : Controller { public ActionResult Details(int

  • 0

Controller to get an image:

public class PicturesSmallController : Controller
{
  public ActionResult Details(int id)
  {
    PictureSmallManager m = new PictureSmallManager();
    PictureSmall p = m.Load(id);
    ImageFormat imageFormat = ImageHelper.ConvertToImageFormat(p.ContentType);
    return p.Trunk != null ? File(p.Trunk, p.ContentType) : null;
  }
}

and a view:

<script type="text/javascript">
  $(document).ready(function () {
  var picsSmall = $('#picturesSmall');
  picsSmall.toggle();
  var url = '@Url.Action("Details", "PicsSmall")';
  var ai = {
    id: 69
  };
  $.ajax({
    type: "POST",
    url: url,
    contentType: 'application/json; charset=utf-8',
    data: JSON.stringify(ai),
    success: function (returndata) {
        picsSmall.append($('<img/>', {
          src: returndata,
          alt: 'some text'
        }));
      select.show('slow');
    }
  }
 );
});
</script>
<div id="picturesSmall"></div>
<div id="picturesBig"></div>

in result I do not see any picture on the page but I got the same result in FireBug:

<div id="picsSmall" style="display: block;">
<img src="�����JFIF��`�`���� ...... �d��:1�g�" alt="some text">
</div>

I have two questions:

  1. I would like to display image correctly. Could you tell me what is wrong here? I am not good in mvc.
  2. I have two the same images the first one is small and the second is big. I would like to show the big image when user click the small. What is the best way to implement it?

If I understand right when picture is loaded to the client side I have to save it in ViewBag. If it’s correct, what is the best way to synchronize small and big pictures (should I use array or object on the client side)? Are there any other ways?
Sorry, it looks more complex than I expected.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T16:45:17+00:00Added an answer on June 6, 2026 at 4:45 pm

    You are returning image bytes from your action. You can’t set raw bytes as source, but can use Data URI scheme as source. You’ll need to change format you’ve returned from your action to be properly formatted string with base64 encoded bytes of the image. Note that some browsers have restrictions on size of the data.

    Sample from Wikipedia page:

    <img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUA
    AAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO
    9TXL0Y4OHwAAAABJRU5ErkJggg==" alt="Red dot">
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this Model public class SalesModelView { [Key] public int SaleId { get;
Controller public ActionResult Create() { return View(new PageViewModel()); } [HttpPost] public ActionResult Create(Page page)
To get the image path in Controller I use the following method: class AssetsController
Here is my JsonResult in my controller: // // GET: /Home/GetTags/ public JsonResult GetTags()
public class RegisterSubscription { public string ID { get; set; } public string Description
I have a controller as follows that returns a byte[] public class ImageController :
I have a simple controller which returns images: public class ImageController : Controller {
My controller get datas from database model, and sends them to view. In view
Example: I have a view controller and get rid of it. But there's still
What's wrong with this function: function() { $.get('/controller/action', function(data) { $('#temporaryPhotos').text(data); } ); return

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.