c# – MVC Error: ‘object’ does not contain a definition for ” – Education Career Blog

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">

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

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

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

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


      <% } %>


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.



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


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”.

Leave a Comment