Пример #1
0
        // To protect from overposting attacks, enable the specific properties you want to bind to.
        // For more details, see https://aka.ms/RazorPagesCRUD.
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            _context.Attach(Person).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!PersonExists(Person.ID))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(RedirectToPage("./Index"));
        }
Пример #2
0
        // To protect from overposting attacks, see https://aka.ms/RazorPagesCRUD
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            _context.Persons.Add(new Person(Person.Name, Person.Age));
            await _context.SaveChangesAsync();

            // var emptyStudent = new PersonVM();
            //
            // if (await TryUpdateModelAsync<PersonVM>(
            //         emptyStudent,
            //         "student",   // Prefix for form value.
            //         s => s.Name, s => s.Age))
            // {
            //     _context.Persons.Add(Person);
            //     await _context.SaveChangesAsync();
            //     return RedirectToPage("./Index");
            // }

            return(RedirectToPage("./Index"));
        }