This project is read-only.

Having trouble persisting data to subsequent/prior views

Topics: Troubleshooting, Writing modules
Nov 17, 2012 at 8:27 PM

I am able to save user input data on the front-end (it's saved in my module's PartRecord in the DB). But I am having some difficulty going "Back" or displaying it on a summary page.

I think my controller code is the only thing relevant to post:

    public ActionResult Details()
        var askUs = new AskUsViewModel();
        var shape = _orchardServices.New.AskUs_Form_Details(AskUs: askUs);
        return new ShapeResult(this, shape);
[HttpPost, Themed]
    public ActionResult Details(string nextButton, AskUsViewModel askUs)
        if ((nextButton != null) && ModelState.IsValid)
            var contact = _askUsService.CreateAskUs(askUs.AskUsPartRecord);
            return RedirectToAction("Confirm");
            var shape = _orchardServices.New.AskUs_Form_Details(AskUs: askUs);
            return new ShapeResult(this, shape);
    public ActionResult Confirm(string backButton, string nextButton)
        var askUs = _askUsService.GetAskUs();
        if (backButton != null)
            return RedirectToAction("Details");
        else if ((nextButton != null) && ModelState.IsValid)
            return RedirectToAction("Submitted");
        return new ShapeResult(this, _orchardServices.New.AskUs_Form_Confirm
                AskUs: askUs

I can't figure out how to retrieve the saved content to display in the Confirm view. This also means I cannot figure out how to display it if the user hits "Back" (I am thinking I have to do a separate ActionResult (like the way it's done in Admin where ActionResults are named Edit or some such thing))

I view the DB table and see that several entries with ID have been inserted. Sorry for the simple question. As always the help/guidance is appreciated.

Nov 18, 2012 at 8:31 AM

I'm sorry, this is not very clear. What are you trying to do, how are you trying it, what are the expected results, and what happens when you try?

Nov 18, 2012 at 6:24 PM
Edited Nov 18, 2012 at 6:25 PM

I am trying to retrieve data which is saved on one screen (whether hitting "Back" or going to a summary (confirm) screen).

I tried slapping an "int id" on the Confirm ActionResult and making the variable "_askUsService.GetAskUs(id)". This is throwing an expected error ( null entry for parameter 'id' of non-nullable type). So I am trying to research how to get some type of ID on the Details ActionResult in order to persist the data going forward into the Confirm ActionResult. I may just try the DateTime I saved in the Part/PartRecord since it's fairly unique.

The behavior is as follows:

1) User enters information on Details screen. If there are no validation errors, the data gets saved after the user hits Next. The Next button triggers a Redirect to the Confirm ActionResult.

1a) In the backend, the data is saved and I can view a List in the Admin Dashboard (as well as a Details view of each individual item). My thinking is probably incorrect in this: there is an ID being placed in the database. I just thought that the ID would be something I could use (rather than the DateTimeCreated entity I created) to retrieve it on the front end.

2) When it goes to the Confirm screen, I am trying to re-display what the user input to confirm it. There is a back button so the user can go back and edit the inputs. However, I cannot figure out how to pass the saved data to the Confirm screen, and therefore it's not showing.

3) If the user hits the Back button, it should show the Details form again with the data the user entered populating the inputs for editing. This is again where I may be wrong in my thinking: should I create a new DetailsEdit ActionResult to populate the inputs. The behavior now is that the form re-displays empty ready for input (if I input again I am just creating another record).

Thanks for the help.

Nov 19, 2012 at 3:30 AM
Edited Nov 19, 2012 at 3:30 AM

I think I have this resolved. Thanks for trying to help @bertrandleroy. I've basically got a wizard working, but I'm not sure it's 100%. My (silly) mistake was in using Shapes. Without them I am able to use an @Html.Hidden + MvcSerializer, which is what I used with MVC and works well.

I've noticed a recent interest in a wizard, and will post some code for any others interested in the coming days. Hopefully it will help someone.