Copied to clipboard

Flag this post as spam?

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


  • gary 385 posts 915 karma points
    Dec 07, 2015 @ 21:31
    gary
    0

    Html. Action for Contact Form Error

    Hi

    Been a long day!

    Cannot get this to run, now tired and need a bit of friendly Umbraco Community assistance, please-

    Ok have controller

    enter image description here

    have model

    enter image description here

    have view

    enter image description here

    Trying to get the form to render using

    @Html.Action("SendMail" , "ContactSurface")

    The error is " A public action method Send Mail was not found on controller G04_733.Controllers.ContactSurfaceController.

    So, it's finding the controller, but what is wrong I can't seem to figure.

    Really hope it's something simple - would be really happy to finish this soon.

    Thanks in advance

    Gary

  • Marc Goodson 1245 posts 8420 karma points MVP 5x c-trib
    Dec 10, 2015 @ 23:30
    Marc Goodson
    0

    Hi Gary

    @Html.Action("SendMail","ContactSurface")
    

    will attempt to write out a 'Child Action' called SendMail on the ContactSurfaceController Surface Controller

    eg.

       [ChildActionOnly]
            public ActionResult SendMail()
            {
    

    but in your screenshot above you have a SendMail action marked as only accepting a 'post' verb.

    Your view is using BeginUmbracoForm and is wired to post to an action called 'HandleContactForm' in your ContactSurfaceController - does that action exist ? or should it be posting to 'SendMail' ?

    You can create a child action on your surface controller to write out your partial view or you can render your partial view containing your form directly from a template, in this way:

    @Html.Partial("~/Views/Partials/YourLoginView.cshtml", new ContactViewModel()); 
    

    In your surface controller there are also two special helpers you can use: CurrentUmbracoPage to return to the Umbraco current page and keep the modelstate intact or use RedirectToCurrentUmbracoPage to clear the modelstate and return to the current page.

     if (!ModelState.IsValid){
                      ModelState.AddModelError("", "you can add custom error messages to modelstate");
                    return CurrentUmbracoPage();
    }
    else {
    
    //do stuff
    return RedirectToCurrentUmbracoPage();
    }
    

    if that helps ?

  • gary 385 posts 915 karma points
    Dec 11, 2015 @ 18:57
    gary
    0

    Hi Marc

    Thank you so much for taking the time to help. Apologies for taking so long to reply.

    Will have another look at this tomorrow and will for sure be using your ideas.

    Thanks again

    Gary

  • Leo 22 posts 93 karma points
    Dec 11, 2015 @ 20:38
    Leo
    0

    Just curious, I saw this method of a contact form but I also was in the backoffice of my site and saw a Form creation tool package. Which one was the more "standard" way of doing a contact form and why?

  • Marc Goodson 1245 posts 8420 karma points MVP 5x c-trib
    Dec 12, 2015 @ 00:59
    Marc Goodson
    0

    Hi Leo

    Yes the form creation package you are seeing is 'Umbraco Forms' it is a really quick way to create forms to use in your Umbraco site; it is a paid for package (€99 for a domain licence) http://umbraco.com/products-and-support/forms/ but you can check it out for free if you install locally and run on localhost. It's definitely worth exploring what it can do; particularly if you want to avoid developing custom solutions all the time or have editors, who need to create forms quickly without developer assistance. It's possible to extend too; so when a form is posted you can integrate with other services easily etc,

    However in some circumstances, depending on what you are trying to achieve with the posted data; it might be easier for you, particularly if you are a developer with MVC experience, to handle a form post with a surface controller; you then kind of arguably have more control over the html of the form and the handling of the data that is posted; but it's also arguable for something that is as simple as a contact form, just use Umbraco Forms,

    Often it comes down to personal preference, and what you need to deliver for a particular project; rather than a standard way. Umbraco forms does so much for you, for very little outlay, but if you don't need that functionality, you are not forced to use it.

  • Leo 22 posts 93 karma points
    Dec 12, 2015 @ 21:09
    Leo
    0

    Thanks! Great explanation. As an MVC developer, I have no qualms about using the standard controller/view method. Although, I do have to learn a bit more about how this "SurfaceController" works. But it seems pretty straightfroward from the little I've seen thus far. I didn't realize that the umbraco forms were "pay-to-play" lol.

Please Sign in or register to post replies

Write your reply to:

Draft