In my asp.net MVC 4 project, I like to safe something from a partial view, which is when a user clicks for "more details". Saving the data is no problem, closing the partial view is no problem, open the partial view is not a problem, it's when my model is not valid (when a user forgets to mark something) The result is that my partial view is returned, but not inside the view where it should be. Its just viewed as a standalone page.
View:
@model Evaluatietool.ViewModels.EvaluatorWijzigenOPViewModel
<h3>@ViewBag.Message</h3>
@using (Html.BeginForm("ChangeEvaluator", "Ontwikkelplan"))
{
@Html.ValidationSummary(true)
@Html.HiddenFor(model => model.oldEvalAccount)
@Html.HiddenFor(model => model.selectedMedewerkerAccount)
@Html.HiddenFor(model => model.eval);
@Html.HiddenFor(model => model.countMedewerkers);
...
...
<div class="Buttons">
<input type="submit" value="Submit" />
@Ajax.ActionLink("Sluiten", "Evaluatorenlijst", new AjaxOptions { OnSuccess = "HideResultDiv" })
</div>
}
Controller:
[HttpPost]
public ActionResult ChangeEvaluator(EvaluatorWijzigenOPViewModel ewopvm)
{
if (ModelState.IsValid)
{
if (ewopvm.selectedObjects != null)
{
ewopvm.selectedObjects.Add(ewopvm.selectedMedewerkerAccount);
}
else
{
ewopvm.selectedObjects = new List<string>();
ewopvm.selectedObjects.Add(ewopvm.selectedMedewerkerAccount);
}
Ontwikkelplannen op = new Ontwikkelplannen();
Evaluaties e = new Evaluaties();
foreach (string s in ewopvm.selectedObjects)
{
op.ChangeEvaluator(ewopvm.newEvalAccount, ewopvm.oldEvalAccount, s, ewopvm.eval);
}
return RedirectToAction("Evaluatorenlijst");
}
return PartialView("EvaluatorWijzigenPartial", ewopvm);
}
The link that calls the partial view
@Ajax.ActionLink(item.Evaluator1.Naam, "EvaluatorWijzigenPartial", new { id = item.ID, eval = true }, new AjaxOptions { UpdateTargetId = "EvaluatorWijzigen", OnComplete = "ShowResultDiv"})