Beispiel #1
0
        // GET: Posts/Edit/5
        public async Task <IActionResult> Edit(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var post = await _context.Posts.SingleOrDefaultAsync(m => m.ID == id);

            if (post == null)
            {
                return(NotFound());
            }

            var categories = _context.Categories.Select(x => new { Id = x.Name, Value = x.Name });

            var role = _context.Posts.Where(p => p.ID == id).Include(p => p.Category);



            var model = new PostCategoryviewModel();


            model.CategoryList = new SelectList(categories, "Id", "Value", role.First().Category.Name);
            model.Post         = post;



            return(View(model));
        }
Beispiel #2
0
        // GET: Posts/Create
        public IActionResult Create()
        {
            var categories = _context.Categories.Select(x => new { Id = x.Name, Value = x.Name });

            var model = new PostCategoryviewModel();

            model.CategoryList = new SelectList(categories, "Id", "Value");

            return(View(model));
        }