コード例 #1
0
        public IActionResult Create(Country item)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            try
            {
                return(Ok(_countryRepository.Create(item)));
            }
            catch
            {
                return(BadRequest(ModelState)); //or can throw new Exception
            }
        }
コード例 #2
0
 public ActionResult Create(Country country)
 {
     try
     {
         if (ModelState.IsValid)
         {
             countryRepository.Create(country);
             return(RedirectToAction("Index"));
         }
         return(View(country));
     }
     catch
     {
         // return RedirectToAction("Create");
         return(View());
     }
 }