Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • James Jackson-South 489 posts 1747 karma points c-trib
    Mar 24, 2015 @ 15:14
    James Jackson-South
    0

    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).

    /// <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))
    
  • Dave Woestenborghs 3504 posts 12133 karma points MVP 8x admin c-trib
    Mar 24, 2015 @ 18:58
    Dave Woestenborghs
    0

    Can you post the code of your surface controller ? Surface controllers normally have different routing than pages.

     

    Dave

  • Tom Steer 161 posts 596 karma points
    Mar 24, 2015 @ 20:44
    Tom Steer
    0

    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

  • Jason Prothero 422 posts 1243 karma points c-trib
    Dec 16, 2015 @ 23:46
    Jason Prothero
    0

    Anyone find a solution to this issue? I'm currently bumping up against it now.

    Thanks, Jason

  • James Jackson-South 489 posts 1747 karma points c-trib
    Dec 17, 2015 @ 00:30
    James Jackson-South
    0

    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

  • Jason Prothero 422 posts 1243 karma points c-trib
    Dec 17, 2015 @ 18:41
Please Sign in or register to post replies

Write your reply to:

Draft