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 7914573
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T14:09:54+00:00 2026-06-03T14:09:54+00:00

I have same action in a controller that fetch from db for example a

  • 0

I have same action in a controller that fetch from db for example a Employee with a name, age, image (byte[]).

So I store the info in ViewBag. Then in the View the specific code for the image is:

<img src="@ViewBag.Image" alt="Logo" />

But when I see the content of the response I have:

<img src="System.something.FileContentResult" alt="Logo" />

I have seen a lot of examples that gets the FileContentResult from a specific Action in a Controller for example:

(The code is an example only)

public ActionResult GetEmployeeImage (int id){
    byte[] byteArray = GetImageFromDB(id);
    FileContentData file = new File (byteArray,"image/jpg");
    return file;
}

And then render the image with:

<img src="@Url.Action("GetEmployeeImage", "Home", new { id = ViewBag.Id })" alt="Em" />

But I dont want that because I already have the image.

How can I render it to the View throw the ViewBag?

Thanks!

PD: Rendering image in a View is the same but was not concluded

  • 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-03T14:09:56+00:00Added an answer on June 3, 2026 at 2:09 pm

    One possibility is to use the data URI scheme. Bear in mind though that this will work only on browsers that support it. The idea is that you would embed the image data as base64 string into the src attribute of the img tag:

    <img src="data:image/jpg;base64,@(Html.Raw(Convert.ToBase64String((byte[])ViewBag.Image)))" alt="" />
    

    If on the other hand you want a solution that works in all browsers you will have to use a controller action to serve the image. So in the initial request fetch only the id, name and age properties of the employee and not the image. Then write a controller action that will take the employee id as parameter, query the database, fetch the corresponding image and return it as file result. Then inside the view point the src attribute of the img tag to this controller action.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have link for example domain.com/de/controler/action?param=value and I want make actionlink to keep same
I would like to have 4 actions with the same name (controller methods may
Simply scenario -- I have two buttons both of which call the same controller/action.
I have the folowing gsp page: <g:form controller=?? action=??> <h1>Search</h1> <g:submitButton name=search value=Search/> <div
I have a number of URLs that fit a {controller}/{action} pattern. My problem is
Both are delegates and have the same signature, but I can not use Action
Is it possible to have same table name on different schema with different data
I have called a view from another with Html.Action method. I want to call
I am using ajaxSubmitButton to POST data to my controller. That controller action then
I do have my own Controller in Magento, that has been done by following

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.