New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
BeginUmbracoForm in custom routes still doesn't work #13836
Comments
Hi there @callumbwhyte! Firstly, a big thank you for raising this issue. Every piece of feedback we receive helps us to make Umbraco better. We really appreciate your patience while we wait for our team to have a look at this but we wanted to let you know that we see this and share with you the plan for what comes next.
We wish we could work with everyone directly and assess your issue immediately but we're in the fortunate position of having lots of contributions to work with and only a few humans who are able to do it. We are making progress though and in the meantime, we will keep you in the loop and let you know when we have any questions. Thanks, from your friendly Umbraco GitHub bot 🤖 🙂 |
Hi @callumbwhyte.. Thanks for reporting. I understand why this not work. Sadly we was hit by our development environment actually adds the controllers to DI to detect ambiguous constructors 🤦♂️ . Ill make a fix that fall back to use |
Thanks @bergmania! What about the case with requiring |
@callumbwhyte I found another problem, when submitting a form using HttpGet to a surface controller from a page with virtual route, it did not hit the surface controller (because the virtual route has higher priority). Not sure if this is the same, but I doubt. But I can't seem to replicate the other problem. |
don't know if this helps at all, but I was able to get around this issue by overiding the action in htmlattributs in the form definition
|
@bergmania If my virtual route action looks like this:
...and my surface controller does this:
...it's as if the page has been loaded blank, i.e. with no state. TempData, ModelState etc are all as if the page has been loaded from scratch. Adding I think you've hit the issue there with the priority thing. After |
Now surface controller requests always has higher priority than other. So if this is both a surface controller request and a virtual page request, it will execute the surface controller.
* Fixed issue mentioned in #13836 Now surface controller requests always has higher priority than other. So if this is both a surface controller request and a virtual page request, it will execute the surface controller. * Moved some login into private methods * More clean up * Clean up * Only handle valid candidates
Which Umbraco version are you using? (Please write the exact version, example: 10.1.0)
10.4.0 / 11.1.0
Bug summary
As raised in #13017 and #13333
BeginUmbracoForm
doesn't work in custom routes.This was supposedly fixed in #13103 and released in v10.4.0 and v11.1.0, however this isn't quite the case...
Attempting to use post to a
SurfaceController
in a custom route will result in an exception.Specifics
The exception that is thrown states the route's controller can't be found in the DI container.
UmbracoVirtualPageRoute
callsGetRequiredService
on the controller type. This throws an exception if the service can't be found. As far as I understand, controllers of typeUmbracoPageController
aren't automatically registered so this will blow up in most cases... Clearly another approach is needed to get an instance of the controller type.For now this can be worked around by registering the controller in the DI container:
This allows the form to be submitted and breakpoints in the
SurfaceController
are hit 🙌However, returning
CurrentUmbracoPage()
from inside theSurfaceController
does not work – the page just refreshes and all modelstate is lost. This is particularly unhelpful when it's necessary to return a validation message or set something inTempData
.Further investigation has shown this works correctly only when an
[HttpGet]
attribute is added to the route's target action.Steps to reproduce
Code samples to replicate can be found in the description of #13103.
Upon copying the exact code into a v10.4.0 / v11.1.0 project and submitting the form, the DI error is present.
Removing the
[HttpGet]
attribute from theUmbracoPageController
actions means the page just refreshes, modelstate is lost, etc.Expected result / actual result
It shouldn't be a requirement to register controllers in DI or apply specific HTTP verbs to the outer page controller in order to post to a
SurfaceController
within a custom route.This item has been added to our backlog AB#26881
The text was updated successfully, but these errors were encountered: