コード例 #1
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,Descr,GermanyRegionId")] GermanyCity germanyCity)
        {
            if (id != germanyCity.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(germanyCity);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!GermanyCityExists(germanyCity.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["GermanyRegionId"] = new SelectList(_context.GermanyRegions, "Id", "Descr", germanyCity.GermanyRegionId);
            return(View(germanyCity));
        }
コード例 #2
0
        public async Task <IActionResult> Create([Bind("Id,Descr,GermanyRegionId")] GermanyCity germanyCity)
        {
            if (ModelState.IsValid)
            {
                _context.Add(germanyCity);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["GermanyRegionId"] = new SelectList(_context.GermanyRegions, "Id", "Descr", germanyCity.GermanyRegionId);
            return(View(germanyCity));
        }