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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T10:14:20+00:00 2026-05-30T10:14:20+00:00

I just followed an MVC tutorial on creating an image Gallery, which connects the

  • 0

I just followed an MVC tutorial on creating an image Gallery, which connects the Controller to the data connection, like this:

ImageController.cs:

...
private CustomMembershipDB db = new CustomMembershipDB();

    public ViewResult Index()
    {
        return View(db.lm_pics.ToList());
    }
...

Instead of connecting directly to CustomMembershipDB, I’d like to use my own Model named GalleryModel.cs. I’m thinking this would allow me to create more functionality that just direct data access.

I am not sure how to write this model, or how to reference it in the controller so that it behaves the same way as a direct database connection does now.

Currently, my GalleryModel.cs file looks lke this (edited to correct error):

namespace LMProj_MVC.Models
{
    public class GalleryModel
    {
        public string Picname { get; set; }
        public string Decription{ get; set; }
        public int Userid { get; set; }
    }

    public class PicDBContext : CustomMembershipDB
    {
        public DbSet<GalleryModel> GalleryModel { get; set; }
    }
}

I’d like to be able to show the gallery using an iEnumberable list as I am doing now, in addition to creating other methods. Could someone tell me what I’m missing?

  • 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-05-30T10:14:21+00:00Added an answer on May 30, 2026 at 10:14 am

    You need to create an instance of your model object for each of your database pictures. You could use LINQ to do this, for example:

    var picSummaries = db.lm_pics.Select(pic => new GalleryModel{
        Picname = pic.Name,
        Description = pic.Description,
        Userid = pic.User.Id
    });
    

    Or you could use a for each loop:

    var picSummaries = new List<GalleryModel>();
    
     foreach (var pic in db.lm_pics)
        {
            picSummaries.Add(new GalleryModel{
                Picname = pic.Name,
                Description = pic.Description,
                Userid = pic.User.Id
            });
        }
    

    then return the view as before:

    return View(picSummaries);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Virtual host not working in the NETWORK I just followed this site tutorial, Virtual
I've just followed this example from Wordpress and I have successfully added an extra
I followed this instruction but not worked for me. I just wanna install and
I have started creating an app which uses a core data stack at the
I just followed a simple hibernate struts tutorial and succesfully made db calls through
I've just followed the Railscast tutorial: http://railscasts.com/episodes/262-trees-with-ancestry Is it possible to paginate results from
I'm following the MVC Music Store tutorial, but I've just gotten a bit stuck
i followed all of these steps in this tutorial: Created a validator class public
I just followed the instructions from this page ( http://www.alexkorn.com/blog/2011/03/getting-php-mysql-running-amazon-ec2/ ) to setup apache
Just followed the Authlogic tutorial. I am getting uninitialized constant Authlogic when I try

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.