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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T12:08:19+00:00 2026-05-24T12:08:19+00:00

I have generated a strongly-type view from a model class that I have created

  • 0

I have generated a strongly-type view from a model class that I have created from scratch. I have used the List as the scaffold template. The error appears at the foreach line with the model object.

View:

@model IEnumerable<HockeyPoolStats.Models.Player>

@{
    ViewBag.Title = "Index";
}

@foreach (var item in Model) {
    <tr>
        <td>
            @Html.DisplayFor(modelItem => item.Team_Id)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.Rank)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.PlayerName)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.PlayerTeam)
        </td>
[...]

Controller:

 public class PlayerController : Controller
    {

        private HockeyPoolStatsDB _db = new HockeyPoolStatsDB();

        //
        // GET: /Player/


    public ActionResult Index()
    {
        Player _player = new Player();
        _db.Players.Add(_player);
        var model = _db.Players;

        return View(model);
    }

    }

DbContext

public class HockeyPoolStatsDB : DbContext
    {

        public DbSet<Player> Players { get; set; }
        public DbSet<Team> Teams { get; set; }
        public DbSet<Goalie> Goalies { get; set; }


    }

I don’t understand why model is null. This means that the controller isn’t passing the model to the view correctly?

Screenshot

  • 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-24T12:08:21+00:00Added an answer on May 24, 2026 at 12:08 pm

    It more likely means that _db.Players is returning null.

    Set a breakpoint and step through it and verify that _db.Players is actually returning a list of players.

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

Sidebar

Related Questions

OK so I have a strongly-typed Customer Details view that takes a Customer object
I have a strongly typed view of type ProductListingViewModel which in turn contains a
is there any way to re-build a strongly typed view when the model class
I have a generated txt file. This file has certain lines that are superfluous,
I have long tables generated by datagrid control that go beyond the page width.
I have an automatically generated XML file for the game that I run. It
I have a core file generated on a remote system that I don't have
I have a number of generated .sql files that I want to run in
I have a page that is generated which inserts an HTML comment near the
I have 3 PDF documents that are generated on the fly by a legacy

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.