Quantcast
Channel: ASP.NET Core
Viewing all articles
Browse latest Browse all 9386

Problem trying to use ViewModel to Scaffold Controller

$
0
0

Very new to ASP.net Core 2 MVC but trying to figure things out. 

I have created a ViewModel:

ublic class PeopleStateViewModel
    {
        public People People { get; set; }
        public StatesDictionary States { get; set; }

        public PeopleStateViewModel(People people)
        {
            People = people;
            States = new StatesDictionary();
        }
    }

I Have these two models:

    public class People
    {
        public int ID { get; set; }
        [StringLength(60, MinimumLength = 2)]
        [Required]
        public string FirstName { get; set; }
        [StringLength(60, MinimumLength = 2)]
        [Required]
        public string LastName { get; set; }
    }



        public static SelectList StateSelectList
        {
            get { return new SelectList(StateDictionary, "Value", "Key"); }
        }
        public static readonly IDictionary<string, string>
            StateDictionary = new Dictionary<string, string> {
                {"Choose...",""}
                , { "Alabama", "AL" }
                , { "Alaska", "AK" }
                , { "Arizona", "AZ" }
                , { "Arkansas", "AR" }
                , { "California", "CA" }
                // code continues to add states...
            };
    }

I try to create a controller using MVC  Controller with views, using Entity Framework.

I then get this error:

I want to be able to use data from both classes on a view... 

Any help is appreciated. 


Viewing all articles
Browse latest Browse all 9386

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>