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 28 posts 185 karma points
    May 27, 2016 @ 10:22
    jaco steketee
    0

    Use Page Name into form

    I have created a form using a surface controller. The form is working correctly, but i want to send the page name through the form. Can someone please tell how i should get this ?

    Kind regards, Jaco

    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 ReserveerSurfaceController : SurfaceController { // GET: ReserveerSurface public ActionResult Index() { return PartialView("ReserveerView", new ReserveerViewModel()); }

        [HttpPost]
        public ActionResult HandleFormSubmit(ReserveerViewModel 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 = "Reservering van uw website";
            message.From = new System.Net.Mail.MailAddress(model.Email, model.VoorNaam + " " + model.AchterNaam);
            message.Body = "Voornaam:  " + model.VoorNaam + "<br />" + "Achternaam:  " + model.AchterNaam + "<br />" + "Email adres:  " + model.Email + "<br />" + "Telefoon:  " +
              model.Telefoon + "<br />" + "Datum:  " + model.date_booking + "<br />" + "Tijd:  " + model.time_booking + "<br />" + "Aantal Volwassenen:  " + model.Volwassenen + "<br />" + "Aantal Kinderen:  " + model.Kinderen;
            message.IsBodyHtml = true;
            SmtpClient smtp = new SmtpClient();
            smtp.Send(message);
    
    
    
            return RedirectToCurrentUmbracoPage();
    
        }
    }
    

    }

  • Bijesh Tank 192 posts 419 karma points
    May 27, 2016 @ 10:35
    Bijesh Tank
    100

    Hi Jaco,

    If your controller inherits from SurfaceController then you can access the current page name.

    public class MySurfaceController : SurfaceController
    

    then in your action, something like

    var pageName = CurrentPage.Name;
    

    B.

  • jaco steketee 28 posts 185 karma points
    Jun 02, 2016 @ 07:25
    jaco steketee
    0

    Great, Thank you very much :):) That did the trick!

  • Paul Seal 428 posts 2354 karma points MVP 3x c-trib
    May 28, 2016 @ 09:01
    Paul Seal
    0

    if you are trying to access it from within a partial, you can use:

    @{
        string pageName = Umbraco.AssignedContentItem.Name;
    }
    
  • jaco steketee 28 posts 185 karma points
    Jun 02, 2016 @ 07:26
    jaco steketee
    0

    Thank you very much!

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies