Copied to clipboard

Flag this post as spam?

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


  • jaco steketee 30 posts 187 karma points
    Jan 19, 2017 @ 10:14
    jaco steketee
    0

    Contact form Surface Controller

    Hi i hope someone can help me, Ive created a contact form. But when i update the email adress in the controller (using a web editor) the changes dont work. Do i have to rebuild in order to change this ?

    Best Regards,

    Jaco

  • Alex Skrypnyk 6133 posts 23952 karma points MVP 7x admin c-trib
    Jan 19, 2017 @ 22:27
    Alex Skrypnyk
    0

    Hi Jaco,

    Can you provide code example?

    What do you mean "in the controller (using a web editor)"?

    THanks,

    Alex

  • jaco steketee 30 posts 187 karma points
    Jan 30, 2017 @ 13:35
    jaco steketee
    0

    Hi Alex,

    I tried editing the Controller directly in html on the webserver under controllers. But i have noticed that this doesn't work . When i edited the controller in Visual studio and previewed the publishing i saw that there is also a dll created...So i guess i have to do this in Visual studio.

    using Marstrand.Models;
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Net.Mail;
    using System.Web;
    using System.Web.Mvc;
    using Umbraco.Web.Mvc;
    
    namespace Marstrand.Controllers
    {
        public class ContactFormSurfaceController : SurfaceController
        {
            // GET: ContactFormSurface
            public ActionResult Index()
            {
                return PartialView("ContactForm", new ContactFormViewModel());
            }
    
            [HttpPost]
            public ActionResult HandleFormSubmit(ContactFormViewModel model)
            {
                if (!ModelState.IsValid)
                   return CurrentUmbracoPage();
    
    
                //Hier komt de code om mail te verzenden
                MailMessage message = new MailMessage();
                message.To.Add("[email protected]");
                message.Subject = "ContactFormulier via uw website TEST";
                message.From = new System.Net.Mail.MailAddress(model.EmailAdres, model.VoorNaam + " " + model.AchterNaam);
                message.Body = "Voornaam:  " + model.VoorNaam + "<br />" + "Achternaam:  " + model.AchterNaam + "<br />" + "Email adres:  " 
                + model.EmailAdres + "<br />" + "Telefoon:  " + model.telefoonNummer + "<br />" + "<br />" + "<br />" + model.Bericht;
                message.IsBodyHtml = true;
                SmtpClient smtp = new SmtpClient();
                smtp.Send(message);
    
                TempData["success"] = true;
                return RedirectToCurrentUmbracoPage();
    
            }
        }
    }
    

    Thanks,

    Jaco

  • Dennis Adolfi 1082 posts 6446 karma points MVP 5x c-trib
    Jan 30, 2017 @ 14:45
    Dennis Adolfi
    3

    Hi jaco.

    If you place your controllers in the /App_Code folder they get compiled at runtime. That way you can make live changes using a web editor/FTP and they will run instantly.

    But if you have your controllers outside /App_Code, like for instance/Controllers, your code needs to combine (build the dll:s) and then you need to publish the dll with the same name as your project/solution for your changes to take affect. That probably why you see your changes in Visual Studio, since it builds when you run your project.

    So, either move your controllers to the /App_Code folder or compile locally and publish the dll:s.

    Hope this makes sense!! Best of luck!

  • jaco steketee 30 posts 187 karma points
    Jan 30, 2017 @ 19:56
    jaco steketee
    0

    Hi Dennis,

    Thank you very much :) but can i just create a folder named App_Code and move the controller to this folder ?

  • Dennis Adolfi 1082 posts 6446 karma points MVP 5x c-trib
    Feb 06, 2017 @ 07:14
    Dennis Adolfi
    0

    Yes, you can jaco.

    Did it work out for you?

  • Alex Skrypnyk 6133 posts 23952 karma points MVP 7x admin c-trib
    Jan 30, 2017 @ 20:42
    Alex Skrypnyk
    0

    Hi Jaco,

    Yes, you can just create App_Code folder and move the controller there.

    "App_Code" - reserved asp.net name of folder for compiled at runtime.

    Hope it will help you.

    Thanks,

    Alex

Please Sign in or register to post replies

Write your reply to:

Draft