public IActionResult Test()
        {
            var viewModel = new DtoA
            {
                Id    = 3,
                DtoBs = new[]
                {
                    new DtoB {
                        Id = 4
                    },
                    new DtoB
                    {
                        Id    = 5,
                        DtoCs = new[]
                        {
                            new DtoC {
                                Id = 5
                            },
                            new DtoC {
                                Id = 6
                            },
                        }
                    },
                }
            };

            return(View(viewModel));
        }
        public IActionResult PostTest(DtoA dtoA)
        {
            if (!ModelState.IsValid)
            {
                var ModelStateErrors = ModelState.Where(x => x.Value.Errors.Count > 0).ToDictionary(k => k.Key, k => k.Value.Errors.Select(e => e.ErrorMessage).ToArray());

                ViewData["Error"] = string.Join("<br>", ModelStateErrors.Select(d => $"\"{d.Key}\" : { string.Join("", d.Value)}"));
            }
            return(View(dtoA));
        }
Example #3
0
 public IActionResult Index(DtoA dto)
 {
     return(RedirectToAction("Index"));
 }