{"action":"created","issue":{"url":"https://api.github.com/repos/aspnet/Scaffolding/issues/247","repository_url":"https://api.github.com/repos/aspnet/Scaffolding","labels_url":"https://api.github.com/repos/aspnet/Scaffolding/issues/247/labels{/name}","comments_url":"https://api.github.com/repos/aspnet/Scaffolding/issues/247/comments","events_url":"https://api.github.com/repos/aspnet/Scaffolding/issues/247/events","html_url":"https://github.com/aspnet/Scaffolding/issues/247","id":158568438,"number":247,"title":"MVC 6 Entity Scaffolding bug","user":{"login":"bwoodard007","id":9634760,"avatar_url":"https://avatars.githubusercontent.com/u/9634760?v=3","gravatar_id":"","url":"https://api.github.com/users/bwoodard007","html_url":"https://github.com/bwoodard007","followers_url":"https://api.github.com/users/bwoodard007/followers","following_url":"https://api.github.com/users/bwoodard007/following{/other_user}","gists_url":"https://api.github.com/users/bwoodard007/gists{/gist_id}","starred_url":"https://api.github.com/users/bwoodard007/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bwoodard007/subscriptions","organizations_url":"https://api.github.com/users/bwoodard007/orgs","repos_url":"https://api.github.com/users/bwoodard007/repos","events_url":"https://api.github.com/users/bwoodard007/events{/privacy}","received_events_url":"https://api.github.com/users/bwoodard007/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2016-06-05T18:54:11Z","updated_at":"2016-06-06T15:42:58Z","closed_at":null,"body":"``` c#\r\n    public class Quiz\r\n    {\r\n        public int Id { get; set; }\r\n        [Required, MaxLength(255)]\r\n        public string Title { get; set; }\r\n        [Required]\r\n        public DateTime DateCreated { get; set; }\r\n        public Difficulty DifficultyLevel { get; set; }\r\n    }\r\n    public enum Difficulty\r\n    {\r\n        Beginner = 1,\r\n        Intermediate,\r\n        Advanced\r\n    }\r\n   public class Question\r\n    {\r\n        public int Id { get; set; }\r\n        [Required]\r\n        public Quiz Quiz { get; set; }\r\n\r\n        [Required]\r\n        public int QuizId { get; set; }\r\n\r\n        [Required]\r\n        public string QuestionContent { get; set; }\r\n    }\r\n\r\n```\r\n\r\nI created a new controller using MVC + Entity Framework, it generated the following code on Create:\r\n\r\n\r\n``` c#\r\n[HttpPost]\r\n        [ValidateAntiForgeryToken]\r\n        public async Task<IActionResult> Create([Bind(\"Id,QuestionContent,QuizId\")] Question question)\r\n        {\r\n            if (ModelState.IsValid)\r\n            {\r\n                _context.Add(question);\r\n                await _context.SaveChangesAsync();\r\n                return RedirectToAction(\"Index\");\r\n            }\r\n            ViewData[\"QuizId\"] = new SelectList(_context.Quizzes, \"Id\", \"Quiz\", question.QuizId);\r\n            return View(question);\r\n        }\r\n```\r\n\r\n\r\nIn my view \r\n``` html\r\n@model MeMeA.Guru.Entities.Question\r\n\r\n<h2>Create</h2>\r\n\r\n<form asp-action=\"Create\">\r\n    <div class=\"form-horizontal\">\r\n        <h4>Question</h4>\r\n        <hr />\r\n        <div asp-validation-summary=\"ModelOnly\" class=\"text-danger\"></div>\r\n        <div class=\"form-group\">\r\n            <label asp-for=\"QuestionContent\" class=\"col-md-2 control-label\"></label>\r\n            <div class=\"col-md-10\">\r\n                <input asp-for=\"QuestionContent\" class=\"form-control\" />\r\n                <span asp-validation-for=\"QuestionContent\" class=\"text-danger\" />\r\n            </div>\r\n        </div>\r\n        <div class=\"form-group\">\r\n            <label asp-for=\"QuizId\" class=\"col-md-2 control-label\"></label>\r\n            <div class=\"col-md-10\">\r\n                <select asp-for=\"QuizId\" class =\"form-control\" asp-items=\"ViewBag.QuizId\"></select>\r\n            </div>\r\n        </div>\r\n        <div class=\"form-group\">\r\n            <div class=\"col-md-offset-2 col-md-10\">\r\n                <input type=\"submit\" value=\"Create\" class=\"btn btn-default\" />\r\n            </div>\r\n        </div>\r\n    </div>\r\n</form>\r\n\r\n<div>\r\n    <a asp-action=\"Index\">Back to List</a>\r\n</div>\r\n\r\n@section Scripts {\r\n    @{await Html.RenderPartialAsync(\"_ValidationScriptsPartial\");}\r\n}\r\n```\r\n\r\n\r\nThe view always generates an error\r\n```\r\nAn unhandled exception occurred while processing the request.\r\nNullReferenceException: Object reference not set to an instance of an object.\r\n\r\nMicrosoft.AspNetCore.Mvc.Rendering.MultiSelectList.Eval(Object container, String expression)`\r\n```\r\n\r\nI just wanted to let you guys know this error occurs in the default code generation when adding a controller and view."},"comment":{"url":"https://api.github.com/repos/aspnet/Scaffolding/issues/comments/223998850","html_url":"https://github.com/aspnet/Scaffolding/issues/247#issuecomment-223998850","issue_url":"https://api.github.com/repos/aspnet/Scaffolding/issues/247","id":223998850,"user":{"login":"bwoodard007","id":9634760,"avatar_url":"https://avatars.githubusercontent.com/u/9634760?v=3","gravatar_id":"","url":"https://api.github.com/users/bwoodard007","html_url":"https://github.com/bwoodard007","followers_url":"https://api.github.com/users/bwoodard007/followers","following_url":"https://api.github.com/users/bwoodard007/following{/other_user}","gists_url":"https://api.github.com/users/bwoodard007/gists{/gist_id}","starred_url":"https://api.github.com/users/bwoodard007/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bwoodard007/subscriptions","organizations_url":"https://api.github.com/users/bwoodard007/orgs","repos_url":"https://api.github.com/users/bwoodard007/repos","events_url":"https://api.github.com/users/bwoodard007/events{/privacy}","received_events_url":"https://api.github.com/users/bwoodard007/received_events","type":"User","site_admin":false},"created_at":"2016-06-06T15:42:58Z","updated_at":"2016-06-06T15:42:58Z","body":"No it's not null, I stepped through with the debugger the actual error happens on the view."}}
{"actor":{"display_login":"bwoodard007"}}