I am trying to create a contact form in my Umbraco (7.7.1 build) and I am hitting a few issues. I'm not sure if there is a go to package for sending contact messages or not but my main requirement is to send an email from a contact form.
I tried the code share tutorial on youtube but kept getting this error
I tried excluding the models folder in App_Data but there was no option only to exclude the files and I also tried rebuilding which fails on several namespaces not having a assembly reference ('Models', 'ContactModel', 'EmailAddressAttribute' 'EmailAddress').
If anyone can help me with either, that would be great.
So the key parts to getting things up and running are:
A model (cs class file, can be saved anywhere, but typically I'd create a Models directory on the site and save it there)
A controller (called ContactSurfaceController.cs in this case) in the controllers directory. This controller needs a couple of methods, but for the purposes of getting your form displaying, you need a method called "RenderForm"
A partial view - this will be returned from the RenderAction method in the controller - I typically create a subdirectory called Forms under Views/Partials and save the Partial View there.
So to figure out what is happening are you able to post the code you have and detail where you have the various "bits" saved.
What is the URL to the YouTube video ?
In terms of "goto" - Umbraco Forms is obviously a commercial package that you can use. Alternatively, and this is purely a guess (someone else might be able to confirm) one possibility is the starter kits might have a contact form and source code for you to reference as part of your learning experience ?
Hope the above helps - feel free to post your code and the community will help out.
I followed it practically to the letter but changed the project reference to my own - which I believe to be right as i'm wondering if my set up is a cause of the fault.
This being the sites hosted online and I download the files via ftp and get a connection to the database still and manage to run a local version of the site - but only through web matrix 3.
What I have been doing is open web matrix and then launch visual studio from there, then as already mentioned I just followed the video.
One thing I forget is to reference the controller as an Umbraco controller (SurfaceController) If you haven't done this then this could be what is causing you the issue!
The surface controller needs to be called when declaring the controller. So if you had a controller called ContactSurfaceController which i believe you do you should start the controller as followed:
public class ContactSurfaceContoller : SurfaceController{
public ActionResults RenderForm()
{
return PartialView("~/Views/Partials/LinkToYourForm.cshtml");
}
}
I believe the surface controller call means that the controller is built into where Umbraco looks for its DLL files.
If this isn't the issue could you share the code you have for the model, view and controller please?
Just wondering and hopefully a silly question, but you are compiling your code via Visual Studio and there is a dll file in the bin directory for your project code ? I ask, as you mention Web Matrix, something I have no idea about, and so wondered if it doesn't compile code... Random thought, but trying to help :-)
David - think the only thing left is to spin up a test site, drop in your code and see what happens - might be able to work it out.
I am trying to finish another project so could look into it tomorrow if that is OK...
The other thought is, are you able to debug the site, ie try going to the page and placing a breakpoint in your controller - does the break point get hit ?
I just realised I haven't posted the Error on this thread this is the error I am receiving.
No route in the route table matches the supplied values.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.InvalidOperationException: No route in the route table matches the supplied values.
Source Error:
Line 25: </div>
Line 26:
Line 27: @{ Html.RenderAction("RenderForm", "ContactSurface"); }
Line 28:
Line 29:
This is what I get on my local, I will try placing a breakpoint and report back what happens
Ok, I have gotten a bit futher with this. So after a bit more googling I read about adding the files to the AppCode folder, so I copied out the model and controller file and pasted them in the AppCode folder and tryed again, my local build failed in Visual Studio - but when running it in WebMatrix the error message I got was different this time refering to model, error message below:
Compilation Error Description: An error occurred during the
compilation of a resource required to service this request. Please
review the following specific error details and modify your source
code appropriately.
Compiler Error Message: CS0103: The name 'model' does not exist in the
current context
Source Error:
Line 19: if (ModelState.IsValid)
Line 20: {
Line 21: SendEmail(model);
Line 22: return RedirectToCurrentUmbracoPage();
Line 23: }
Umbraco Contact Form
I am trying to create a contact form in my Umbraco (7.7.1 build) and I am hitting a few issues. I'm not sure if there is a go to package for sending contact messages or not but my main requirement is to send an email from a contact form.
I tried the code share tutorial on youtube but kept getting this error
I tried excluding the models folder in App_Data but there was no option only to exclude the files and I also tried rebuilding which fails on several namespaces not having a assembly reference ('Models', 'ContactModel', 'EmailAddressAttribute' 'EmailAddress').
If anyone can help me with either, that would be great.
Hi David
So the key parts to getting things up and running are:
So to figure out what is happening are you able to post the code you have and detail where you have the various "bits" saved.
What is the URL to the YouTube video ?
In terms of "goto" - Umbraco Forms is obviously a commercial package that you can use. Alternatively, and this is purely a guess (someone else might be able to confirm) one possibility is the starter kits might have a contact form and source code for you to reference as part of your learning experience ?
Hope the above helps - feel free to post your code and the community will help out.
Cheers, Nigel
Thank you for your reply Nigel.
So the 3 points you mentioned I had done, which I added while the files where open in visual studio as a web project.
The video I was watching was this: https://www.youtube.com/watch?v=3V0A1AYJbys
I followed it practically to the letter but changed the project reference to my own - which I believe to be right as i'm wondering if my set up is a cause of the fault.
This being the sites hosted online and I download the files via ftp and get a connection to the database still and manage to run a local version of the site - but only through web matrix 3.
What I have been doing is open web matrix and then launch visual studio from there, then as already mentioned I just followed the video.
Hope that sheds a bit more light on the subject.
Hi David,
One thing I forget is to reference the controller as an Umbraco controller (SurfaceController) If you haven't done this then this could be what is causing you the issue!
The surface controller needs to be called when declaring the controller. So if you had a controller called ContactSurfaceController which i believe you do you should start the controller as followed:
I believe the surface controller call means that the controller is built into where Umbraco looks for its DLL files.
If this isn't the issue could you share the code you have for the model, view and controller please?
Thanks, Lewis
Thank you Lewis for your reply - I did see that in another post and unfortunately it didn't work for me.
however here is my code:
ContactModel.cs (located in Models within the main project)
ContactSurfaceController.cs (located in Controllers within the main project)
_Contact.cshtml (Located in View/Partials/Contact/)
and finally the code I am using on the page which I wish to call the form has these elements:
Hope that helps.
Anyone able to help with this - I cant seem to see whats going wrong?
Hi David
Just wondering and hopefully a silly question, but you are compiling your code via Visual Studio and there is a dll file in the bin directory for your project code ? I ask, as you mention Web Matrix, something I have no idea about, and so wondered if it doesn't compile code... Random thought, but trying to help :-)
Nigel
HI Nigel - thank you for your reply.
I just looked - there are dll files in the bin directory and I have been compiling within visual studio.
David - think the only thing left is to spin up a test site, drop in your code and see what happens - might be able to work it out.
I am trying to finish another project so could look into it tomorrow if that is OK...
The other thought is, are you able to debug the site, ie try going to the page and placing a breakpoint in your controller - does the break point get hit ?
Cheers, Nigel
I just realised I haven't posted the Error on this thread this is the error I am receiving.
Source Error:
This is what I get on my local, I will try placing a breakpoint and report back what happens
Ok, I have gotten a bit futher with this. So after a bit more googling I read about adding the files to the AppCode folder, so I copied out the model and controller file and pasted them in the AppCode folder and tryed again, my local build failed in Visual Studio - but when running it in WebMatrix the error message I got was different this time refering to model, error message below:
Hey David
You aren't passing in the model on the Submit Method, ie
Hope this helps progress things...
Cheers
Nigel
is working on a reply...