public async Task <IActionResult> Create(
            [Bind(nameof(FileList.Name), nameof(FileList.FileNames))] FileList fileList)
        {
            if (ModelState.IsValid)
            {
                _context.Add(fileList);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }

            return(View(fileList));
        }
예제 #2
0
        public async Task <IActionResult> Create([Bind("Name")] FileList fileList)
        {
            if (ModelState.IsValid)
            {
                if (string.Equals("Joe", fileList.Name, StringComparison.OrdinalIgnoreCase))
                {
                    throw new InvalidOperationException("Joe has been barred");
                }

                _context.Add(fileList);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }

            var viewData = new ViewDataDictionary <FileList>(ViewData, fileList);

            return(new ViewResult
            {
                TempData = TempData,
                ViewData = viewData,
                ViewEngine = _viewEngine,
            });
        }