Click here to Skip to main content
15,896,346 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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):
C#
<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):
C#
[HttpPost]
public virtual ActionResult Review(Person model)
{
     return View("Parts/Review", model);
}



This is the confirmation view (Parts/Review.cshtml):
C#
<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!
Posted

1 solution

"script>
function showReview() {
Review('@Url.Action("Review", HttpContext.Current.Request.RequestContext.RouteData.Values["controller"].ToString())', $("#Confirmation"));
}"

Is this being turned in to correct values on the client side ? If this is a .js file, it won't. Either way, I like to create a block of variables in a script block in my view, and put the rest of my js in to .js files.

If you're just showing a confirmation page, why do you need to make an AJAX call at all ? What is the server doing for you here, if you're confirming a save, but not yet saving ?
 
Share this answer
 
Comments
Member 10542810 22-Jan-14 22:45pm    
Hi, Christian. I am not following your question about the .js files. The "<script>" content is contained in a separate .js file; I included it within the "view" code for ease of documenting the code.

Maybe confirmation is not the correct word here. I need the end user to be able to review the form's content (it is a rather large form that covers many tabs within the wizard) before they make that final submit. I was hoping to take advantage of the EF connection when redisplaying the data to the end user.
Christian Graus 22-Jan-14 22:49pm    
If it's a seperate JS file, then MVC will not parse that file to run the code you've put in there ( unless it started to do that in version 4). Check your source on the client side in Chrome and make sure it reads the way you expect it to.

OK, I understand, it's a summary that you're showing, of data from previous pages. If the data is in the database, then I don't see why this would not work. But I think you're saying it's in the session ? Have you set breakpoints on that final AJAX call to see what the data on the server is, and what it is returning ?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900