VahidN/DNTIdentity

Don't Show ModelState Errors in _PartialView

pMonfared opened this issue · 2 comments

I Create two method (Render, Edit,Create) as Partial :

[AjaxOnly]
        public async Task<IActionResult> Render([FromBody]ModelIdViewModel modelvm)
        {
            var zones = AutoMapper.Mapper.Map(_siteOptions.Value.EducationallevelOfTheCeoes, new List<SelectListItem>());
            var modelVm = new RateViewModel { EducationallevelOfTheCeoes = zones };
            if (string.IsNullOrWhiteSpace(modelvm?.Id))
            {
                return PartialView("_Create", modelVm);
            }

            var model = await _rateService.FindByIdAsync(Convert.ToInt32(modelvm.Id)).ConfigureAwait(false);
            if (model == null)
            {
                ModelState.AddModelError("", NotFound);
                return PartialView("_Create");
            }
            AutoMapper.Mapper.Map(model, modelVm);
            var selectItems = modelVm.EducationallevelOfTheCeoes.Select(s => new SelectListItem
            {
                Text = s.Text,
                Value = s.Value,
                Selected = s.Value == model.EducationallevelOfTheCeoId.ToString()
            });
            modelVm.EducationallevelOfTheCeoes = selectItems.ToList();
            return PartialView("_Create", model: modelVm);
        }

        [AjaxOnly]
        [HttpPost]
        [ValidateAntiForgeryToken]
        public async Task<IActionResult> Edit(RateViewModel modelvm)
        {
            if (ModelState.IsValid)
            {
                    var result = await _rateService.UpdateAsync(modelvm);
                    if (result.Succeeded)
                    {
                        return Json(new { success = true });
                    }
                    ModelState.AddErrorsFromResult(result);
            }
            return PartialView("_Create", model: modelvm);
        }

and Create _PartialViews by this link

but when send and response erorrs : i don't see in any alert (partial)

You should have this line in your code

@{ await Html.RenderPartialAsync("_CustomValidationSummary").ConfigureAwait(false); }
lock commented

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related problems.