コード例 #1
0
        public ActionResult AddWriter(Writer p)
        {
            ValidationResult result = writerValidator.Validate(p);

            if (result.IsValid)
            {
                wm.WriterAddBL(p);
                return(RedirectToAction("Index"));
            }
            else
            {
                foreach (var item in result.Errors)
                {
                    ModelState.AddModelError(item.PropertyName, item.ErrorMessage);
                }
            }
            return(View());
        }
        public ActionResult AddWriter(Writer writer)
        {
            WriterValidator  writerValidator  = new WriterValidator();
            ValidationResult validationResult = writerValidator.Validate(writer);

            if (validationResult.IsValid)
            {
                writerManager.WriterAddBL(writer);
                return(RedirectToAction("Index"));
            }
            else
            {
                foreach (var item in validationResult.Errors)
                {
                    ModelState.AddModelError(item.PropertyName, item.ErrorMessage);
                }
            }
            return(View());
        }