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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T08:05:50+00:00 2026-06-18T08:05:50+00:00

I am new to MVC. I have saved the image and some data but

  • 0

I am new to MVC.I have saved the image and some data but can’t display the saved images. I want to display all saved images in the main page.

Model: Get the db list from model

public List<Products> GenreList()
        {
}

Controller

public ActionResult MYsample()
{
    var MyList = storeDB.GenreList();
    var a= MyList.Count;

    if (a != null)
    {
        foreach (var li in MyList)
        {
            return File(li.fileContent, li.mimeType,li.fileName);
        }
    }
    return View(MyList);
}

View

    @foreach (var item in Model)
    {
            <img src="@Url.Action("MYsample", "HomeController", new { id = item.ProductID })" alt="@item.Productname" />
    }  
  • 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-18T08:05:51+00:00Added an answer on June 18, 2026 at 8:05 am

    You could start by writing a controller action that will serve the images to the response stream:

    public ActionResult Image(int id)
    {
        // you should add a method to your repository that returns the image 
        // record from the id
        Products image = storeDB.Get(id);
        return File(image.fileContent, image.mimeType);
    }
    

    and then in your main controller action send the list of images to the view:

    public ActionResult MySample()
    {
        var model = storeDB.GenreList();
        return View(model);
    }
    

    and then in your strongly typed view loop through the images and generate an <img> tag for each image by pointing its src property to the newly created controller action:

    @model MyList
    @foreach (var li in MyList)
    {
        <img src="@Url.Action("Image", new { id = li.Id })" alt="" />
    }
    

    If you don’t want to have a separate controller action that will query the database and retrieve the image record from an id you could use the data URI scheme. Bear in mind though that this is not supported by all browsers.

    So the idea is that your controller action will send the image data to the view:

    public ActionResult MySample()
    {
        var model = storeDB.GenreList();
        return View(model);
    }
    

    and then inside your strongly typed view you could loop through the list and generate the proper <img> tag:

    @model MyList
    @foreach (var li in MyList)
    {
        <img src="src="data:@(li.mimeType);base64,@(Html.Raw(Convert.ToBase64String(li.fileContent)))" alt="" />
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am new to MVC and have a grasp of the basic model, but
I have started a new mvc project and clicked on project\properties\web - use local
I am new to MVC and EF and I have a question. I have
Pretty new to MVC and the like. I have a class the looks like
New to MVC, so hopefully this will be pretty simple. I have an HTML
I’m fairly new at C# and MVC and have used lambdas on certain occasions,
I'm recently new in MVC technology and i'm with a difficult I have a
I am just new in MVC 3. I have a html view which contain
I am new to MVC and facing one issue. I have a xml file
I have a new asp.net mvc project and i am trying to figure out

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.