I need to create a confirmation page at the conclusion of a wizard style form. The issue I have is, the foreign keys are not remaining populated with the values entered on the form. Below is a sample of my code.
This is the form's view (Form/Edit.cshtml):
<script>
function showReview() {
Review('@Url.Action("Review", HttpContext.Current.Request.RequestContext.RouteData.Values["controller"].ToString())', $("#Confirmation"));
}
function Review(url, target) {
$.post(url, $("form").serialize(), function(data) {
target.html(data);
});
}
</script>
@using (Html.BeginForm("Edit", "Form", FormMethod.Post, new Dictionary<string, object> { { "id", "FormId" } }))
{
@Html.LabelFor(m => m.LastName)
@Html.EditorFor(m => m.LastName)
@Html.ValidationMessageFor(m => m.LastName)
@Html.LabelFor(m => m.FirstName)
@Html.EditorFor(m => m.FirstName)
@Html.ValidationMessageFor(m => m.FirstName)
@Html.DropDownList("SuffixID", (IEnumerable<SelectListItem>) ViewBag.Suffix)
}
This is my controller (FormController.cs):
[HttpPost]
public virtual ActionResult Review(Person model)
{
return View("Parts/Review", model);
}
This is the confirmation view (Parts/Review.cshtml):
<div id="Confirmation">
@Html.DisplayTextFor(m => m.LastName),
@Html.DisplayTextFor(m => m.FirstName)
@Html.DisplayTextFor(m => m.SuffixLookup.Name)
</div>
When I turn on the debugger, model.SuffixLookup is null. The model.SuffixId contains the correct value. After I save my data, the EF model does come back with the model.SuffixLookup content correctly. I can't save the data before the confirmation, I have to somehow refresh the model before loading the confirmation view.
Please help...I have been searching all day for a solution. I don't feel this should be hard to figure out but being new to MVC, I have struggled long enough.
TIA!