예제 #1
0
        public async Task <IActionResult> Edit(int id, [Bind("TheLoaiXeId,TenTheLoaiXe,LoaiXeId")] TheLoaiXe theLoaiXe)
        {
            if (id != theLoaiXe.TheLoaiXeId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(theLoaiXe);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!TheLoaiXeExists(theLoaiXe.TheLoaiXeId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["LoaiXeId"] = new SelectList(_context.LoaiXes, "LoaiXeId", "LoaiXeId", theLoaiXe.LoaiXeId);
            return(View(theLoaiXe));
        }
예제 #2
0
        public async Task <IActionResult> Create([Bind("TheLoaiXeId,TenTheLoaiXe,LoaiXeId")] TheLoaiXe theLoaiXe)
        {
            if (ModelState.IsValid)
            {
                _context.Add(theLoaiXe);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["LoaiXeId"] = new SelectList(_context.LoaiXes, "LoaiXeId", "LoaiXeId", theLoaiXe.LoaiXeId);
            return(View(theLoaiXe));
        }