Note that there are some explanatory texts on larger screens.

plurals
  1. POAccessing objects inside model passed to Razor View in ASP.NET MVC 3
    primarykey
    data
    text
    <p>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.</p> <pre><code>@model BeerRecommender.Models.Beer @{ ViewBag.Title = "Details"; } &lt;h2&gt;@Html.DisplayFor(model =&gt; model.Name)&lt;/h2&gt; &lt;fieldset&gt; &lt;legend&gt;Details&lt;/legend&gt; &lt;div class="display-label"&gt;Style: @Html.DisplayFor(model =&gt; model.Style.Name)&lt;/div&gt; &lt;div class="display-label"&gt;Brewery: @Html.DisplayFor(model =&gt; model.Brewery.Name)&lt;/div&gt; &lt;/fieldset&gt; </code></pre> <p>Here is the Beer class:</p> <pre><code>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&lt;City&gt; Cities { get; set; } public ICollection&lt;Tag&gt; Tags { get; set; } public Style Style { get; set; } public string Name { get; set; } public Brewery Brewery { get; set; } } </code></pre> <p>...and here is the Brewery class:</p> <pre><code>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&lt;Beer&gt; Beers { get; set; } public City City { get; set; } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload