Copied to clipboard

Flag this post as spam?

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


  • Aki 43 posts 214 karma points
    Jan 10, 2016 @ 01:48
    Aki
    0

    Controller routes and Post request from FormPost gives an error

    Hi Im trying to make a Email Verification on my webpage for a newsletter ..

    Im Using a Route Tabel to Make it a Link in a email.

        RouteTable.Routes.MapRoute(
        "",
        "Verify/Newsletter/{contentId}/{verificationHash}",
        new
        {
            controller = "Newsletter",
            action = "Verify",
            id = UrlParameter.Optional
        });
    

    The Surface controller is controling the Partial view for the Newsletter form and a post including the Verifiy Url path

    public ActionResult RenderSubscriptionFormPartialView()
    {
        return PartialView("Partials/Newsletter/SubscriptionForm", new MailinglistSubscriptionModel());
    }
    
    // GET: Newsletter/Subscribe
    [HttpPost]
    [ValidateAntiForgeryToken]
    public ActionResult Subscribe(MailinglistSubscriptionModel model)
    {
    
            return RedirectToCurrentUmbracoPage();
    }
    
     // GET: Newsletter/Verify
    public ActionResult Verify(int contentId, string verificationHash)
    {
        // Verification success
    
        return Redirect("/");
    }
    

    The ting is the Subscribe ActionResult breakes when i make the Route in the route tabel

    and the same with Verify ...

    What am i doing wrong ? The error i get is this..

    Stack Trace:     
    [InvalidOperationException: Could not find a Surface controller route in the RouteTable for controller name Newsletter]
           Umbraco.Web.Mvc.RenderRouteHandler.HandlePostedValues(RequestContext requestContext, PostedDataProxyInfo postedInfo) +667
           Umbraco.Web.Mvc.RenderRouteHandler.GetHandlerForRoute(RequestContext requestContext, PublishedContentRequest publishedContentRequest) +69
           Umbraco.Web.Mvc.RenderRouteHandler.GetHttpHandler(RequestContext requestContext) +114
           System.Web.Routing.UrlRoutingModule.PostResolveRequestCache(HttpContextBase context) +174
           Umbraco.Web.UmbracoModule.RewriteToUmbracoHandler(HttpContextBase context, PublishedContentRequest pcr) +163
           Umbraco.Web.UmbracoModule.ProcessRequest(HttpContextBase httpContext) +417
           Umbraco.Web.UmbracoModule.<Init>b__8(Object sender, EventArgs e) +80
           System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +200
           System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +70
    

    A possible solution is to seperate the Controller out in to 2 one for the default action and one for Route.....

  • Nicholas Westby 2045 posts 7032 karma points c-trib
    Jan 10, 2016 @ 05:11
    Nicholas Westby
    0

    I don't see why you are trying to register a route for your surface controller. For one, surface controllers generate a route for you. Secondly, surface controllers use a mechanism other than the URL to perform routing.

    See here for information on the routing that does not require a particular URL: https://github.com/Nicholas-Westby/LearnUmbraco7/blob/ab9da855fb3a31c816117931ac1997afdc47a82b/Chapter%2006%20-%20Surface%2C%20WebAPI%20and%20RenderMVC%20Controllers/02%20-%20Surface%20Controllers.md#special-routing

    You can scroll up that page for information about the default routes Umbraco generates for surface controllers.

  • Aki 43 posts 214 karma points
    Jan 10, 2016 @ 17:51
    Aki
    0

    The main reason was to bunch together Functions in a controller that made sense to have together .

    The Web site Would be somthing like this..

    Newsletter SubscribeForm - A partial View with a Webform

    Newsletter Subscribe Post - the post to submit data to umbraco and Create a newsletter

    Newsletter Verify - The route from a site that Verifies the Registered email http://URL/Verify/Newsletter/{ID}/{VerificationCode}

    The address in then included in a email send to the User under post ...

  • Nicholas Westby 2045 posts 7032 karma points c-trib
    Jan 10, 2016 @ 20:31
    Nicholas Westby
    0

    If you are going to define your own route rather than use the route automatically created by the surface controller, perhaps you should consider a RenderMvcController. See here: http://stackoverflow.com/a/27526619/2052963

    A RenderMvcController is similar to a surface controller, except you need to create your route for your RenderMvcController, which may be appropriate considering you are attempting to create your own route.

Please Sign in or register to post replies

Write your reply to:

Draft