예제 #1
0
        public IActionResult Index()
        {
            var model = new BooleanInputsViewModel();

            model.Messages.Add($"GET values: {nameof(model.IsImportant)} = {model.IsImportant}, {nameof(model.IsActive)} = {model.IsActive}");
            return(View(model));
        }
예제 #2
0
        public IActionResult Index(BooleanInputsViewModel model)
        {
            model.Messages.Add($"POST values: {nameof(model.IsImportant)} = {model.IsImportant}, {nameof(model.IsActive)} = {model.IsActive}");

            // This does NOT work:
            //model.IsActive = !model.IsActive;
            //model.IsImportant = !model.IsImportant;
            //model.Text += "*";

            // This works:
            this.ModelState[nameof(model.Text)].RawValue       += "*";
            this.ModelState[nameof(model.IsActive)].RawValue    = !model.IsActive;
            this.ModelState[nameof(model.IsImportant)].RawValue = !model.IsImportant;

            model.Messages.Add($"Negated POST values: {nameof(model.IsImportant)} = {model.IsImportant}, {nameof(model.IsActive)} = {model.IsActive}");
            return(this.View(model));
        }