无法使用模型类&QUOT

无法使用模型类&QUOT

本文介绍了无法使用模型类"不包含类的名称和QUOT deffination;的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我下面的mvc MysicStore,项目。在我的模型类,我有Genre.cs

i am following Mvc MysicStore , Project . In my model class i have Genre.cs

namespace MvcMusicStore.Models
{
    public class Genre
    {
        public int GenreId { get; set; }
        public string Name { get; set; }
        public string Descriptio { get; set; }

        public List<Album> albums { get; set; }

    }
}

和同样的2个类,如Artis.cs专辑,CS和Genre.cs。

and same way 2 more classes like Artis.cs Album,cs and Genre.cs .

Genre.cs

namespace MvcMusicStore.Models
{
    public partial class Genre
    {
        public int GenreId { get; set; }
        public string Name { get; set; }
        public string Description { get; set; }
        public List<Album> Albums { get; set; }
    }
}

Album.cs

namespace MvcMusicStore.Models
{
    public class Album
    {
        public int AlbumId     { get; set; }
        public int GenreId     { get; set; }
        public int ArtistId    { get; set; }

        public string Title    { get; set; }

        public decimal Price   { get; set; }
        public string AlbumUrl { get; set; }

        public Genre genre     { get; set; }
        public Artist artist   { get; set; }
    }
}

我的问题是,当我尝试使用这些类样本数据它说:

My problem is that when i try to use these classes with sample data it says

我已经确定没有命名空间的问题,我创建了一个类SampleData.cs已经下code,让误差

i have made sure there are no namespace issues and i have created a class SampleData.cs that has following code that gives error

new List<Album>
            {
                new Album { Title = "The Best Of Men At Work",
                Genre = genres.Single(g => g.Name == "Rock"),
                Price = 8.99M, Artist = artists.Single(a => a.Name == "Men At Work")
                , AlbumArtUrl = "/Content/Images/placeholder.gif" },

它为我上述的错误此code什么错呢?

it shows me above mentioned error for this code whats wrong with it ?

推荐答案

我觉得你的财产是用小写和您尝试访问为类型。尝试重命名它。

I think your property is written in lowercase and you try to access it as Genre. Try renaming it.

这是因为你的专辑类没有一个类型属性,但一个体裁属性。

It's because your Album class doesn't have a Genre property, but a genreproperty.

而不是

public Genre genre     { get; set; }

尝试

public Genre Genre     { get; set; }

这篇关于无法使用模型类&QUOT;不包含类的名称和QUOT deffination;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-16 00:56