View:
<p>Parent ViewData: @ViewData["Test"]</p>
@Html.Action("MemberSignup","MemberSignupSurface")
PartialView:
<p>PartialView ViewData: @ViewData["Test"]</p>
@using (Html.BeginUmbracoForm<MemberSignupSurfaceController>
("MemberSignupSubmit", "MemberSignupSurfaceController",FormMethod.Post))
{
<!-- Some form controls -->
<input type="submit" value="Signup" />
}
Controller:
public class MemberSignupSurfaceController : SurfaceController
{
public ActionResult MemberSignup()
{
ViewData["Test"] = "From MemberSignup";
// Do database stuff and create model from that
return PartialView("MemberSignupView", model);
}
[HttpPost]
public ActionResult MemberSignupSubmit(MemberViewModel model)
{
ViewData["Test"] = "From MemberSignupSubmit";
if (ModelState.IsValid)
{
// Redirect to success using TempData
}
else
{
return CurrentUmbracoPage();
}
}
}
When my page load MemberSignup
is called and the page shows
Parent ViewData:
PartialView ViewData: From MemberSignup
Then when i submit the form on the partial view with invalid input so it won't validate and it calls CurrentUmbracoPage()
in the action MemberSignupSubmit
I get the following:
Parent ViewData: From MemberSignupSubmit
PartialView ViewData: From MemberSignup
If i use @Html.Partial
to render my partial view both viewbags shows the same value set from the submit action.
I've tried TempData
but it is not working either. Is there really no way to pass anything back to the partial view after i return from the submit action when using @Html.Action
to render a partial view form.
The overall problem I am trying to solve is to popluate a dropdown in my form with values from the database. Using @Html.Partial
don't allow me to do this but have a working viewbag.