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.