ASP.NET MVC Validation in Partial View and return to Parent view

前端 未结 1 749
青春惊慌失措
青春惊慌失措 2020-12-30 05:35

My Background

I am working on first serious project using ASP.NET MVC 4. I am working on web development since classic ASP days and have got good ho

相关标签:
1条回答
  • 2020-12-30 06:00

    You need to show the parent view not the child one, so the action should look like:

    [HttpPost]
        public ActionResult SubmitReview(ChildViewModel model)
        {
                 var parentViewModel = write init code here;
                parentViewModel.ChildModel = model;
    
            if (ModelState.IsValid )
            {
    
                return View("Index", parentViewModel );
            }
    
            ModelState.AddModelError("", "Some Error.");
            return View("Index", parentViewModel );
        }
    
    0 讨论(0)
提交回复
热议问题