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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T18:44:24+00:00 2026-06-16T18:44:24+00:00

I’m new to MVC and have this simple Problem (I think). I have a

  • 0

I’m new to MVC and have this simple Problem (I think).
I have a DbContext

public class UsersContext : DbContext
{
    public UsersContext() : base("Share_DB") {}
    public DbSet<ItemDB> Items { get; set; }
}

which contains a list of items with id and Title:

[Table("Items")]
public class ItemDB
{
    [Key]
    [DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)]
    public int Id { get; set; }
    public string Title { get; set; }
}

and I want to bind a list with all the itemes in the Database table to the model. However I can’t figure out how to do that.

In the View (cshtml file) I guess I have define which model I have to use ( @model XXX.Models.ItemModel ) then Display it with something like:

<ul>
@foreach (XXX.Models.ItemModel.ItemDB item in @Items)
{
    <li>@item.Title</li>
}
</ul>

However it can’t find the @Items property is not found. How do I write this?

  • 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-16T18:44:25+00:00Added an answer on June 16, 2026 at 6:44 pm

    The way MVC works is when you return a view in your controller, whatever gets passed to View() ends up as the Model property. In other words:

    public ActionResult Index()
    {
        return View("Hello World");
    }
    

    Will pass the string “Hello World” to your View. Then at the top of your Index.cshtml file, you need to declare the model type:

    @model string
    

    And usage becomes:

    <div>@Model</div>
    

    In your case, you just need to pass your list of Items to the view, and tell it to expect the right type of model:

    public ActionResult Index()
    {
        using (var db = new UsersContext()) 
        {
            var items = db.Items.ToList();
    
            return View(items);
        }
    }
    

    and then in your view:

    @model IEnumerable<ItemDB>
    

    and you can use it as:

    @foreach (var item in Model)
    {
        <div>@item.Title</item>
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have just tried to save a simple *.rtf file with some websites and
this is what i have right now Drawing an RSS feed into the php,
I am doing a simple coin flipping experiment for class that involves flipping a
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
This could be a duplicate question, but I have no idea what search terms
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have an MVC Razor view @{ ViewBag.Title = Index; var c = (char)146;
I have been unable to fix a problem with Java Unicode and encoding. The

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.