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{ Art开发者_StackOverflow中文版ists = 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.
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".
精彩评论