Umbraco MVC On form submit redirect to another form with prefilled value
All,
I am tryign to redirect from one form to another and have everything correct except when I redirect to the second form i think the HTTP POST is submitting the form again on page load so that means that my validation is coming up and is not correct.
My first forms action result where I redirect to the second form taking TempData for passing from controller to controller
public ActionResult FooterFindADistributorSubmit(FindADistributorFormModel model)
{
var distributorPage = Umbraco.TypedContentAtRoot().DescendantsOrSelf<IPublishedContent>().Where(x => x.DocumentTypeAlias == "findADistributor").First();
var distId = Convert.ToInt32(distributorPage.Id);
if (ModelState.IsValid)
{
TempData["distZip"] = model.ZipCode;
return RedirectToUmbracoPage(distId);
}
return CurrentUmbracoPage();
}
Hi
Try putting [HttpGet] or [HttpPost] above your action results to specify which should run on the get or the post. This should eliminate unexpected behaviour.
thanks for the reply - did try specifying a GET for the form that was receiving the value and a POST For the form that was sending the value however the main form (the one in the screenshot) still validates the value before hitting the search button.
I am out of ideas but this did appear to alleviate some other headaches i had...
It only hits the breakpoint once - basically my workflow is this:
User submits a form from the footer
this form has an HttpPost action result for submitting the form
The input is captured via TempData and then saved into my model, and redirects to the umbraco page i need it too
The controller for the main form then takes the value and places it into another model that has a zipcode and results public method.
I pass the model to the view and place the value in the appropriate html attribute for an input
This has an HttpGet action result for getting the data i need.
Furthermore every time i call the main form partial I am passing a new model to it and allowing the controller to set the zipCode method if applicable.
Umbraco MVC On form submit redirect to another form with prefilled value
All,
I am tryign to redirect from one form to another and have everything correct except when I redirect to the second form i think the HTTP POST is submitting the form again on page load so that means that my validation is coming up and is not correct.
My first forms action result where I redirect to the second form taking TempData for passing from controller to controller
My second controller that receives the TempData
My second View that should be filling the value
Here is what my second view looks like after I redirect with the correct value
Why is the form being validated when all I am doing is passing a value through TempData?
Does the RedirectToUmbracoPage do an HTTP POST and then another one when the page loads?
Hi Try putting [HttpGet] or [HttpPost] above your action results to specify which should run on the get or the post. This should eliminate unexpected behaviour.
Kind regards
Paul
Paul,
thanks for the reply - did try specifying a GET for the form that was receiving the value and a POST For the form that was sending the value however the main form (the one in the screenshot) still validates the value before hitting the search button.
I am out of ideas but this did appear to alleviate some other headaches i had...
Any ideas?
If I'm correct you're saying that your form submits twice?
So, the breakpoints get hit twice?
Or does it validate twice? (if so, how do you know?)
I'm asking because I had problems with that recently and I found a solution after a while so I can maybe help.
It only hits the breakpoint once - basically my workflow is this:
The input is captured via TempData and then saved into my model, and redirects to the umbraco page i need it too
The controller for the main form then takes the value and places it into another model that has a zipcode and results public method.
I pass the model to the view and place the value in the appropriate html attribute for an input
Furthermore every time i call the main form partial I am passing a new model to it and allowing the controller to set the zipCode method if applicable.
is working on a reply...