示例#1
0
        public async Task <IActionResult> Create([Bind("Id,Name")] Trainer trainer)
        {
            if (ModelState.IsValid)
            {
                _context.Add(trainer);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(trainer));
        }
        public async Task <IActionResult> Create([Bind("Id,Species,Type")] Pokemon pokemon)
        {
            if (ModelState.IsValid)
            {
                _context.Add(pokemon);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(pokemon));
        }
示例#3
0
        public async Task <IActionResult> Create([Bind("TrainerId,PokemonId,Name")] Catch @catch, int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }
            if (ModelState.IsValid)
            {
                @catch.TrainerId = id.Value;

                _context.Add(@catch);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }

            ViewBag.PokeList = new SelectList(_context.Pokemon.ToList(), "Id", "Species");

            return(View(@catch));
        }