I have page which is loaded from controller MyFormController
, which in turn loads a view component. This view component renders a form.
I need the form to submit to controller SecondaryFormController
, but it always submits back to MyFormController
instead.
I can see in the markup that the generated <form action="/">
outputs the route for MyFormController
but I understand this to be normal behaviour. To my knowledge Umbraco will use the generated and hidden upfrt
to decide where to route to. This is how it behaves on my other forms.
Whatâs happening here that triggers Umbraco to route to MyFormController
rather than SecondaryFormController
?
Hereâs trimmed down version of the code:
MyFormController:
public class MyFormController: RenderController {
public MyFormController() {}
public override IActionResult Index() {
var viewModel = new MyFormControllerViewModel() {
...
}
return CurrentTemplate(viewModel);
}
}
The template for MyFormController.Index:
@inherits UmbracoViewPage < MyApp.MyFormControllerViewModel >
@(await Component.InvokeAsync < MyApp.MyFormControllerMainViewComponent > ())
MyFormControllerMainViewComponent looks like:
public class MyFormControllerMainViewComponent: ViewComponent {
public MyFormControllerMainViewComponent() {
}
public async Task < IViewComponentResult > InvokeAsync() {
return View(new MyViewComponentViewModel())
}
}
The view/template for MyFormControllerMainViewComponent:
@model MyApp.MyViewComponentViewModel
@using(Html.BeginUmbracoForm < MyApp.SecondaryFormController > (
nameof(MyApp.SecondaryFormController.MyTest),
"Update",
null,
) {
<
button type = "submit" >
Update <
/button> <
/div>
}
SecondaryFormController.MyTest:
public class SecondaryFormController: SurfaceController {
public SecondaryFormController() {}
[HttpPost]
[ValidateAntiForgeryToken]
[UnsupportedOSPlatform("browser")]
public async Task < IActionResult > MyTest(MyViewComponentViewModel model) {
// do something
return CurrentUmbracoPage();
}
}
Whatâs happening here? Iâve been pulling my hair out for a while.
Is there a way a can decode/decrypt upfrt
?