Пример #1
0
        public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
        {
            // Creates the person from the input form values
            PersonInputModel inputModel = CreatePersonInput(controllerContext);

            // Use the injected model validator to check if the values are proper
            if (!Validator.IsValid(inputModel))
            {
                bindingContext.ModelState.AddModelError("person.Name", "Please specify a valid name!");

                return(null);
            }

            return(inputModel);
        }
Пример #2
0
        public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
        {
            // Creates the person from the input form values
            PersonInputModel inputModel = new PersonInputModel
            {
                Name = controllerContext.HttpContext.Request.Form["Name"]
            };

            // Use the injected model validator to check if the values are proper
            if (!Validator.IsValid(inputModel)) {
                bindingContext.ModelState.AddModelError("person.Name", "Please specify a valid name!");

                return null;
            }

            return inputModel;
        }