Example #1
0
        public async Task <ActionResult> Delete(int id, IFormCollection collection)
        {
            var entity = new Department();

            await TryUpdateModelAsync(entity);

            try
            {
                var result = await _db.DeleteAsync <Department>(id);

                if (result > 0)
                {
                    return(RedirectToAction(nameof(Index)));
                }
                else
                {
                    ModelState.AddModelError(string.Empty, "删除失败");
                }
            }
            catch (Exception ex)
            {
                ModelState.AddModelError(string.Empty, ex.Message);
            }

            return(View(entity));
        }