C# ASP.NET MVC Basics Modeling and Presenting Data Creating a Data Model

Giulio Vannini
Giulio Vannini
21,922 Points

Help with Model Challenge in ASP.Net MVC basics

I cannot get past with what i wrote! Any ideas?

VideoGame.cs
namespace Treehouse.Models
{
    public class VideoGame
    {

        public int Id
        {
              get
             {
                return Id;
             }
        }

        public string Title
        {
              get
             {
                return Title;
             }

            set
            {
                Title = value;
            }


        }

        public string Description
        {
              get
             {
                return Description;
             }
        }

        public string[] Characters
        {
              get
             {
                return Characters;
             }
        }

        public string Publisher
        {
              get
             {
                return Title;
             }
            set
            {
                Title = value;
            }



        }

        public string DisplayText
        {
            get
            {
                return Title + " (" + Publisher + ")";
            }


        }


    }

}

1 Answer

Seth Kroger
MOD
Seth Kroger
Treehouse Moderator 56,204 Points

Take a look at your getter and setter for Publisher. It looks like you copied and pasted the code but forgot to change the property because you are getting and setting Title instead. It works better and is less error prone if you use the getter/setter shorthand instead.

namespace Treehouse.Models
{
    public class VideoGame
    {
        public int Id { get; set; }
        public string Title { get; set; }
        public string Description { get; set; }
        public string[] Characters { get; set; }
        public string Publisher { get; set; }
        public string DisplayText {
            get
            {
                return Title + " (" + Publisher +")";
            }
        }
    }
}