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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T20:08:53+00:00 2026-05-26T20:08:53+00:00

My beer model has a brewery object but I can’t access the brewery’s properties

  • 0

My beer model has a brewery object but I can’t access the brewery’s properties when I’m in the view. Intellisense seems to think I can access the brewery property but the DisplayFor method doesn’t print anything.

@model BeerRecommender.Models.Beer

@{
ViewBag.Title = "Details";
}

<h2>@Html.DisplayFor(model => model.Name)</h2>

<fieldset>
<legend>Details</legend>

<div class="display-label">Style: @Html.DisplayFor(model => model.Style.Name)</div>
<div class="display-label">Brewery: @Html.DisplayFor(model => model.Brewery.Name)</div>

</fieldset>

Here is the Beer class:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ComponentModel.DataAnnotations;
using BeerRecommender.Models.ViewModels;

namespace BeerRecommender.Models
{
public class Beer
{
    [Key]
    public int BeerID { get; set; }

    public ICollection<City> Cities { get; set; }

    public ICollection<Tag> Tags { get; set; }

    public Style Style { get; set; }

    public string Name { get; set; }

    public Brewery Brewery { get; set; }
}

…and here is the Brewery class:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.ComponentModel.DataAnnotations;

namespace BeerRecommender.Models
{
public class Brewery
{
    [Key]
    public int BreweryID { get; set; }

    public string Name { get; set; }

    public ICollection<Beer> Beers { get; set; }

    public City City { get; set; }
}
}
  • 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-26T20:08:54+00:00Added an answer on May 26, 2026 at 8:08 pm

    How are you loading the Beer class? If this is from say entity framework you will need to call .Include(o=>o.Brewery) in your loading code to include that table . This is assuming EF 4.1 otherwise you need the string name like .Include(“Brewery”) if in 4.0

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

Sidebar

Related Questions

Free as in beer. I can live without the source code. About 10 years
Lets say I have a wine and beer model/controller along with a wine_review and
Let's say that I want to match beer, but don't care about case sensitivity.
Beer <br> Vodka <br> rum <br> whiskey how can you select beer ? or
I am building a beer recipe application in Cocoa. It's has one main window,
It must be obvious, but I can't figure it out. I spent almost a
I've been looking for a free (as in free beer) library that can parse
I'm working on my project: [Beer Pong Management System][1], a Windows Forms application. I
so Here's my query: SELECT b1.beer as beer1, b2.beer as beer2 , b1. price
Given a simple Parsekit grammar. @start = sentence+; sentence = 'beer' container; container =

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.