I'm using the following implementation of UmbracoVirtualNodeRouteHandler to allow me to have an edit page for a dashboard on my site without creating a node. (There really, really is no need for a node, I should just be able to create an ActionResult).
/// <summary>
/// The project virtual node route handler.
/// </summary>
public class ProjectVirtualNodeRouteHandler : UmbracoVirtualNodeRouteHandler
{
/// <summary>
/// returns the <see cref="IPublishedContent"/> associated with the route.
/// </summary>
/// <param name="requestContext">
/// The request context.
/// </param>
/// <param name="umbracoContext">
/// The umbraco context.
/// </param>
/// <returns>
/// The <see cref="IPublishedContent"/>.
/// </returns>
protected override IPublishedContent FindContent(RequestContext requestContext, UmbracoContext umbracoContext)
{
UmbracoHelper helper = new UmbracoHelper(umbracoContext);
string alias = typeof(DashboardPage).Name;
return helper.TypedContentAtRoot()
.First()
.Descendants()
.First(d => d.DocumentTypeAlias.InvariantEquals(alias));
}
}
This, combined with the following route, allows me to render the page with a form on it without creating a node.
RouteTable.Routes.MapUmbracoRoute(
"ProjectEdit",
"Dashboard/Edit/{id}/",
new
{
controller = "DashboardPage",
action = "Edit"
},
new ProjectVirtualNodeRouteHandler());
This all works great until it's time to post the form.
Adding another ActionResult to the same controller (It's a Surface/RenderMVC hybrid) doesn't allow me to post the form at all. I get an error
No route in the route table matches the supplied values.
Moving the ActionResult to another controller allows me to post the form but the RenderModel is now wrong as the FindContent in my ProjectVirtualNodeRouteHandler is intercepting the call even though I am posting to another location.
How can I post from this form from this location without creating a node I shouldn't have to create?
Either implementation of the following markup (typed/untyped) fails miserably.
@using (Html.BeginUmbracoForm<FormsController>("SubmitDashboardForm", null, new { enctype = "multipart/form-data" }, FormMethod.Post))
I've not worked with virtual nodes a great deal but would you not need to create a custom route for your form post aswell? abit like Shannon does here:
Posting a form from a virtual node.
V7.2.1
I'm using the following implementation of
UmbracoVirtualNodeRouteHandler
to allow me to have an edit page for a dashboard on my site without creating a node. (There really, really is no need for a node, I should just be able to create an ActionResult).This, combined with the following route, allows me to render the page with a form on it without creating a node.
This all works great until it's time to post the form.
Adding another
ActionResult
to the same controller (It's a Surface/RenderMVC hybrid) doesn't allow me to post the form at all. I get an errorMoving the
ActionResult
to another controller allows me to post the form but theRenderModel
is now wrong as theFindContent
in myProjectVirtualNodeRouteHandler
is intercepting the call even though I am posting to another location.How can I post from this form from this location without creating a node I shouldn't have to create?
Either implementation of the following markup (typed/untyped) fails miserably.
Can you post the code of your surface controller ? Surface controllers normally have different routing than pages.
Dave
Hey James :)
I've not worked with virtual nodes a great deal but would you not need to create a custom route for your form post aswell? abit like Shannon does here:
https://github.com/Shazwazza/Articulate/blob/master/Articulate/ArticulateRoutes.cs#L183
Cheers,
Tom
Anyone find a solution to this issue? I'm currently bumping up against it now.
Thanks, Jason
Sorry chum,
I don't have access to the codebase anymore that I was working on (contracting) and I can't remember if I ever cracked it.
Here's an updated link to the Articulate codebase. Maybe there is something in there you can use.
https://github.com/Shazwazza/Articulate/blob/7ee1e41e3cea38432cdc624ca8259a60a43501b2/src/Articulate/ArticulateRoutes.cs
I just posted a new forum post here:
https://our.umbraco.org/forum/umbraco-7/using-umbraco-7//73791-getting-an-error-with-custom-routes-could-not-find-a-surface-controller-route-in-the-routetable-for-controller-name-authorization
Hopefully, we can figure out a solution or work-around there.
is working on a reply...