2

So i'm doing a wizard as such located here: how to make a wizard with ASP.Net MVC where each page has its own div but each div is really located on the same page. Now, there are 2 issues...I am new to MVC and wish to do some sort of validation before continuing to the next page. Validation ranges from a simple text box (is there data there?) to is the data in the textbox in the correct format, to is there an item in the drop down list selected, to is there an item in a listbox (mutually exclusive listboxes). So there is a wide range of variety going on, including a few pages will have tables with paging/sorting where the user will select an item from the list and click to modify that item or add a new one so, it will depend on what the user does on the first page to populate the rest of the pages, if necessary. Now, I have tried this:

public ActionResult ContinueToCorr(string Number, string Rev)
    {

        ViewData["DivIsVisible"] = true;
        return RedirectToAction("../Wizard/Index/1");
    }

located from here set div visible fasle in get method of controller yet it doesn't work for me.

Also, I'd like to do the following and I would greatly appreciate any help. Before the user starts the wizard, Id like the user to be presented with a selection page (obviously) then after selection, Id like the web address to be something like this localhost:xxxx/Wizard/'PartNumber'/'PageNumberOfWizard' so if the user is selected part number 12345 and started the wizard, they would be redirected to localhost:xxxx/Wizard/12345/1 (for page 1) and localhost:xxxx/Wizard/12345/2 for page 2 and so on with each page showing the next div and hiding the previous after successful validation.

Finally, I tried to play with the asax file for routing in order to get what I wanted before in a web address but this is what I came up with:

routes.MapRoute(
            "Wizard",                                              // Route name
            "Wizard/{PartNum}/{PageId}",                           // URL with parameters
            new { controller = "Wizard", action = "Index" }  // Parameter defaults
        );

So it looks as if It will always call the Index method of the Wizard controller.

Now I have tried the following in my View pages:

<% Html.BeginForm("ContinueToPage", "Wizard", FormMethod.Post); %>
                        <div class="span-87 buttons">
                            <input type="submit" value="Continue" name="button" />
                        </div>
                    <% Html.EndForm(); %>

Surrounding each button in a form to call a new specific function for that button to start the validation process before continuing onto the next page and the code behind would look like this:

[AcceptVerbs(HttpVerbs.Post)]
    public ActionResult ContinueToCorr(string Number, string Rev)
    {
        //if (String.IsNullOrEmpty(Number))
        //    ModelState.AddModelError("Number", "Number is required");
        //if (String.IsNullOrEmpty(TPSSWRevision))
        //    ModelState.AddModelError("Rev", "Revision is required");
        //if (!ModelState.IsValid)
        //    return View();

        ViewData["DivIsVisible"] = true;
        return RedirectToAction("../Wizard/Index/1");
    }

I'm not sure if thats entirely correct but I just feel as if I am running in circles here. Thanks a lot. Sorry if its so long but I wanted to make it as detailed as possible. Also, I have included this:

<script runat="server">
protected bool DivIsVisible {
    get {
        return ViewData["DivIsVisible"] != null && (bool)ViewData["DivIsVisible"];
    }
}
</script>

in the View as well, still nothing.

Community
  • 1
  • 1
dangerisgo
  • 1,261
  • 3
  • 16
  • 28

1 Answers1

1

I can answer to your first question:

public ActionResult ContinueToCorr(string Number, string Rev)
{
    ViewData["DivIsVisible"] = true;
    return RedirectToAction("../Wizard/Index/1");
}

You are using RedirectToAction, that clears all ViewData. Instead, use:

public ActionResult ContinueToCorr(string Number, string Rev)
{
    ViewData["DivIsVisible"] = true;
    return Index(1);
}

I'm assuming that you have an ActionResult called Index that takes an Int parameter, in your Wizard controller.

Francisco
  • 4,104
  • 3
  • 24
  • 27
  • In my Index() (In this case, this Index has no parameters), I just have a return View(); call, yet when I do that I get an error saying that it cannot find ContinueToCorr.aspx in any location. I thought that if you had a return View() under a function, it looked for the View that was named for that function, in this case Index, no? Am I missing something? – dangerisgo Jul 27 '09 at 16:25
  • Also what would I pass into Index with the parameters? – dangerisgo Jul 27 '09 at 18:31
  • Not always... if you want to force the rendered view, put return View("Index"); I don't understand your second comment. I thought you wanted to pass a "1" into your Index action, because of the routing /Wizard/Index/1 you put there. – Francisco Jul 27 '09 at 20:20
  • So I'm still a bit lost as to how to show/hide divs. I have my setup now so that I pass in the action so lets say the address will be: localhost:xxxx/Wizard/Selection which would call the Selection function. A much better solution, and implementable. But still not sure on how to pass the viewData so that I can show/hide a div. – dangerisgo Jul 28 '09 at 14:27
  • so right now I have one index function which will return View();. When I call return Index(); from the ContinueToCorr function, it does in fact call the Index() function but instead of returning the Index view, it still wants to return the ContinueToCorr view. – dangerisgo Jul 28 '09 at 14:46
  • It depends. If you only want to hide it, just use CSS classes (display:none). Pass your CSS from your viewdata, like viedata["divToBeHidden"]="class='hiddenCSS'"; Just and idea though. Also, did you put return View("Index") instead of return View()? in your ActionResult Index? – Francisco Jul 28 '09 at 18:31