title: Details View Controller method using viewModel
body: <p>I'm still finding my feet with asp.net MVC.</p>
  
  <p>I want to generate a details view from a viewModel but I'm not getting the controller right so its saying I'm passing the incorrect type of model to the view.</p>
  
  <p>The Controller currently is:</p>
  
  <pre><code>    public ActionResult ClubDetails(int clubId)
      {
          //Populate the view
          var clubs = from s in db.Clubs
                      orderby s.Name
                      select s;
          var viewModel = clubs.Select(t =&gt; new ClubDetailsViewModel
          {
              Name = t.Name,
              ShortName = t.ShortName,
              Founded = t.Founded,
              ContactName = t.FirstName + " " + t.LastName,
              Address1 = t.Address1,
              Address2 = t.Address2,
              City = t.City,
              County = t.County,
              Postcode = t.Postcode,
              Telephone = t.Telephone,
              Email = t.Email,
              Bio = t.Bio,
              Website = t.Website,
          });
          return View(viewModel);
      }
  </code></pre>
  
  <p>The viewModel is:</p>
  
  <pre><code>    public class ClubDetailsViewModel
  {
      [Display(Name = "Club Name")]
      public string Name { get; set; }
  
      [Display(Name = "Abbreviation")]
      public string ShortName { get; set; }
  
      [Display(Name = "Founded")]
      [DataType(DataType.Date)]
      [DisplayFormat(DataFormatString = "{0:dd/MM/yyyy}", ApplyFormatInEditMode = true)]
      public DateTime? Founded { get; set; }
  
      [Display(Name = "Contact Name")]
      public string ContactName { get; set; }
  
      [Display(Name = "Address 1")]
      public string Address1 { get; set; }
  
      [Display(Name = "Address 2")]
      public string Address2 { get; set; }
  
      [Display(Name = "City")]
      public string City { get; set; }
  
      [Display(Name = "County")]
      public string County { get; set; }
  
      [Display(Name = "PostCode")]
      public string Postcode { get; set; }
  
      [Display(Name = "Telephone")]
      public string Telephone { get; set; }
  
      [EmailAddress]
      [Display(Name = "Email")]
      public string Email { get; set; }
  
      [Display(Name = "Website")]
      [Url]
      public string Website { get; set; }
  
      [Display(Name = "Bio")]
      public String Bio { get; set; }
  }
  </code></pre>
  
  <p>The view is:</p>
  
  <pre><code>@model GRCWebApp.ViewModels.ClubDetailsViewModel
  
  @{
  ViewBag.Title = "ClubDetails";
  }
  
  &lt;h2&gt;ClubDetails&lt;/h2&gt;
  
  &lt;div&gt;
  &lt;h4&gt;ClubDetailsViewModel&lt;/h4&gt;
  &lt;hr /&gt;
  &lt;dl class="dl-horizontal"&gt;
      &lt;dt&gt;
          @Html.DisplayNameFor(model =&gt; model.Name)
      &lt;/dt&gt;
  
      &lt;dd&gt;
          @Html.DisplayFor(model =&gt; model.Name)
      &lt;/dd&gt;
  
      &lt;dt&gt;
          @Html.DisplayNameFor(model =&gt; model.ShortName)
      &lt;/dt&gt;
  
      &lt;dd&gt;
          @Html.DisplayFor(model =&gt; model.ShortName)
      &lt;/dd&gt;
  
      &lt;dt&gt;
          @Html.DisplayNameFor(model =&gt; model.Founded)
      &lt;/dt&gt;
  
      &lt;dd&gt;
          @Html.DisplayFor(model =&gt; model.Founded)
      &lt;/dd&gt;
  
      &lt;dt&gt;
          @Html.DisplayNameFor(model =&gt; model.ContactName)
      &lt;/dt&gt;
  
      &lt;dd&gt;
          @Html.DisplayFor(model =&gt; model.ContactName)
      &lt;/dd&gt;
  
      &lt;dt&gt;
          @Html.DisplayNameFor(model =&gt; model.Address1)
      &lt;/dt&gt;
  
      &lt;dd&gt;
          @Html.DisplayFor(model =&gt; model.Address1)
      &lt;/dd&gt;
  
      &lt;dt&gt;
          @Html.DisplayNameFor(model =&gt; model.Address2)
      &lt;/dt&gt;
  
      &lt;dd&gt;
          @Html.DisplayFor(model =&gt; model.Address2)
      &lt;/dd&gt;
  
      &lt;dt&gt;
          @Html.DisplayNameFor(model =&gt; model.City)
      &lt;/dt&gt;
  
      &lt;dd&gt;
          @Html.DisplayFor(model =&gt; model.City)
      &lt;/dd&gt;
  
      &lt;dt&gt;
          @Html.DisplayNameFor(model =&gt; model.County)
      &lt;/dt&gt;
  
      &lt;dd&gt;
          @Html.DisplayFor(model =&gt; model.County)
      &lt;/dd&gt;
  
      &lt;dt&gt;
          @Html.DisplayNameFor(model =&gt; model.Postcode)
      &lt;/dt&gt;
  
      &lt;dd&gt;
          @Html.DisplayFor(model =&gt; model.Postcode)
      &lt;/dd&gt;
  
      &lt;dt&gt;
          @Html.DisplayNameFor(model =&gt; model.Telephone)
      &lt;/dt&gt;
  
      &lt;dd&gt;
          @Html.DisplayFor(model =&gt; model.Telephone)
      &lt;/dd&gt;
  
      &lt;dt&gt;
          @Html.DisplayNameFor(model =&gt; model.Email)
      &lt;/dt&gt;
  
      &lt;dd&gt;
          @Html.DisplayFor(model =&gt; model.Email)
      &lt;/dd&gt;
  
      &lt;dt&gt;
          @Html.DisplayNameFor(model =&gt; model.Website)
      &lt;/dt&gt;
  
      &lt;dd&gt;
          @Html.DisplayFor(model =&gt; model.Website)
      &lt;/dd&gt;
  
      &lt;dt&gt;
          @Html.DisplayNameFor(model =&gt; model.Bio)
      &lt;/dt&gt;
  
      &lt;dd&gt;
          @Html.DisplayFor(model =&gt; model.Bio)
      &lt;/dd&gt;
  
  &lt;/dl&gt;
  &lt;/div&gt;
  &lt;p&gt;
  @Html.ActionLink("Edit", "Edit", new { /* id = Model.PrimaryKey */ }) |
  @Html.ActionLink("Back to List", "Index")
  &lt;/p&gt;
  </code></pre>