I need to give user a chance to see what he entered and verify it before data get submitted. When user click on submit form I want to display all data entered in form into separate page. When user clicks verify on that page then data go back to controller that finally submits the data.
I think the main problem is that how to move all form data from one page to another page.
One way to do it would be to create a new controller action, e.g., "VerifySubmission". Submitting your form should post to YourController.VerifiySubmission(). The View for VerifySubmission displays the data so the user can review it, and also writes out the fields as hidden form fields. There is a submit button on this "verify" page, when the user clicks it, it POST's the hidden form fields to your final "FormSubmit" controller action (whatever you have named it), where it gets saved to the database.
EDIT: Also, please update the title of your question so it gives some indication of what question you are asking.
What you want is to have the form posted to the controller. For example, if you are using the Index
page for the submission, your controller code would look something like this
public ActionResult Index()
{
return View();
}
[HttpPost]
public ActionResult Verify(FormCollection form)
{
ViewBag.FormItems = form;
return View();
}
[HttpPost]
public ActionResult Accept(FormCollection form)
{
// Do whatever you need to do to store the data
return View();
}
Now, if your users are submitting information that is in a model, you'll want to actually use that model in place of FormCollection
, and set your View
s to be strongly typed against that model (it'll be much easier to handle doing it as strongly typed model).
Admittedly, setting the ViewBag
to just store the FormCollection
is a lazy way of doing things, but in the absence of knowing what you really want to do, it works. As I said, using a model for the input data would simplify things and make it more robust.
One more approach to transfer data between enter data-confirm-final submit pages is to use TempData that allows you to save state (usually in SessionState) between 2 requests.