views:

23

answers:

1

Hi guys,

I'm currently working my way through the MVC Music Store tutorial. I'm stuck on page 53 at the moment and I was wondering if someone could help me out.

I'm currently receiving the following two errors:

'object' does not contain a definition for 'Artists'

'object' does not contain a definition for 'Genres'

I think I've looked at it for too long now and I can't spot my error. A fresh pair of eyes may do the trick!

Here is the aspx file in which the error occurs:

<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<MvcMovies1.ViewModels.StoreManagerViewModel>" %>
<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
 Edit
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">

    <h2>Edit</h2>
    <% using (Html.BeginForm())
       { %>
      <%: Html.ValidationSummary(true)%>

    <fieldset>
      <legend>Edit Album</legend>
      <%: Html.EditorFor(model => model.Album,
          new object{ Artists = Model.Artists, Genres = Model.Genres }) %>

          <p><input type="submit" value="Save" /></p>


    </fieldset>

      <% } %>

</asp:Content>

And here is the class that this page should be calling from, so to speak:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using MvcMovies1.Models;

namespace MvcMovies1.ViewModels
{
    public class StoreManagerViewModel
    {
        public Album Album { get; set; }
        public List<Artist> Artists { get; set; }
        public List<Genre> Genres { get; set; }
    }
}

PS - I realise some of my names are MvcMovies1, I called it that by mistake but everything is referenced accordingly.

+3  A: 

Replace:

new object{ Artists = Model.Artists, Genres = Model.Genres } 

With:

new { Artists = Model.Artists, Genres = Model.Genres }

In other words, you want to create a new anonymous type. Your syntax above actually attempts to create a new bare object and assign values to the nonexistent properties on object: "Artists" and "Genres".

Kirk Woll
+1 - This mistake is normally caused by intellisense, which sticks the word "object" in when you hit space after the word "new". The only known work arounds are 1) Remember to delete it, 2) type "new{" with no space (it will add the space in when you get the closing "}".
Sohnee
THANK YOU! It was the intelli-sense alright and I think I was looking for something more complicated! I'll mark this as the correct answer once the time limit is up!
TaraWalsh
@Sohnee, that has been the bane of my life for a long time!
DaveDev