I working on a really really simple Umbraco 7 website which i have created on Azure. The main backend functionality I need to get working is a simple Contact form. I wasnt planning on setting up a big VS studio project for such a small website. Initially I thought there might be a simple contact form project that would work on U7 but I couldnt see any projects thta were confirmed to work. So I tried to implement my own simple Ajaxy form based on this tutorial:
The difference is that becuase i have not setup a VS project i didnt put my model or surface controller into the model/controller folders (cause the dont exist in the deploy) I put my code staright into the App_Code folder.
After some errors with references etc... I manage to get a working page. However when i submit my ajax form the surface controller seems to just return the page markup (the page doesnt refresh i just get the page html posted back)
Here is my code:
Model:
using System; using System.ComponentModel.DataAnnotations; using System; using System.ComponentModel.DataAnnotations;
public class ContactViewModel { [Required] public string Name { get; set; }
Controller (simplified it doesnt actually do anything yet):
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; using Umbraco.Web.Mvc; using System.Net.Mail; using System.Net;
public class ContactFormSurfaceController : Umbraco.Web.Mvc.SurfaceController { [HttpPost] [NotChildAction] public ActionResult SendMail(ContactViewModel form) { string retValue = "There was an error submitting the form, please try again later."; if (!ModelState.IsValid) { return Content(retValue); }
<script> function ShowError() { $("#status").removeClass(); $("#status").addClass("alert alert-error"); $("#status").html("<strong>Error!</strong> There was an error posting the contact form. Please try again later."); }
function ShowSuccess() { $("#target").removeClass(); $("#target").addClass("alert alert-success"); } </script>
View (jsut the line that called the partial):
@Html.Partial("ContactForm", new ContactViewModel())
The code above actually givesa 404 error when submitted it says:
HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable. Please review the following URL and make sure that it is spelled correctly.
/umbraco/Surface/ContactFormSurface/SendMail
If i try and changes any of the names deifned in the Ajax call in the partial i get no 404 but the form just posts back the current page.
I guess i have 2 questions:
1. Can i call a surface controller that is in the App_Code folder? if so what am I doing wrong? 2. If this wont work are there any simple contact form projects I may have missed that I can use instead?
Update here is a bit more infomration from the error:
[HttpException]: The controller for path '/umbraco/Surface/ContactForm/SendMail' was not found or does not implement IController. at System.Web.Mvc.DefaultControllerFactory.GetControllerInstance(RequestContext requestContext, Type controllerType)
Umbraco 7 Surfacce Controller Ajax.BeginForm
Hello all,
I working on a really really simple Umbraco 7 website which i have created on Azure. The main backend functionality I need to get working is a simple Contact form. I wasnt planning on setting up a big VS studio project for such a small website. Initially I thought there might be a simple contact form project that would work on U7 but I couldnt see any projects thta were confirmed to work. So I tried to implement my own simple Ajaxy form based on this tutorial:
http://www.systenics.com/blog/creating-an-ajax-enabled-contact-form-in-umbraco-6-with-aspnet-mvc-4-and-twitter-bootstrap/?tag=Umbraco+6
The difference is that becuase i have not setup a VS project i didnt put my model or surface controller into the model/controller folders (cause the dont exist in the deploy) I put my code staright into the App_Code folder.
After some errors with references etc... I manage to get a working page. However when i submit my ajax form the surface controller seems to just return the page markup (the page doesnt refresh i just get the page html posted back)
Here is my code:
Model:
Controller (simplified it doesnt actually do anything yet):
Partial Veiw:
View (jsut the line that called the partial):
The code above actually givesa 404 error when submitted it says:
If i try and changes any of the names deifned in the Ajax call in the partial i get no 404 but the form just posts back the current page.
I guess i have 2 questions:
1. Can i call a surface controller that is in the App_Code folder? if so what am I doing wrong?
2. If this wont work are there any simple contact form projects I may have missed that I can use instead?
Thanks
Lachlann
Update here is a bit more infomration from the error:
This was answered by @Cultiv (Sebastiaan Janssen)
The problem was that I needed to have a namespace defined as the code was executing from the App_Code folder. As soon as I did this my code executed.
Thansk Sebastiaan!
is working on a reply...