Copied to clipboard

Flag this post as spam?

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


  • Mark Evans 86 posts 116 karma points
    Sep 03, 2014 @ 17:47
    Mark Evans
    0

    Accessing page property in a controller

    ive created a basic contact form in umbraco and the when the form page is created, a property (emailaddresses) is populated to list the recepients of that form. 

    i want to access that property within the controller as this is where the form contents are emailed out (to the email addesses listed in this property)....

    the controller is called from a partial view and simply accesses the model properties before sending out an email...

    can i access this property in my controller or would i pass it to the controller from my partial view ?

    PARTIAL VIEW

    @model UmbracoSite.Models.ContactModel

    @using (Html.BeginUmbracoForm("Contact", "ContactSurface", null, new {@class = "contact-form"}))
    {
        @Html.ValidationSummary(false)

        <div>
            @Html.LabelFor(x => x.Name)
            @Html.TextBoxFor(x => x.Name)
            @*@Html.ValidationMessageFor(x => x.Name)*@
        </div>
       
        <div>
            @Html.LabelFor(x => x.Email)
            @Html.TextBoxFor(x => x.Email)
            @*@Html.ValidationMessageFor(x => x.Email)*@
        </div>
       
        <div>
            @Html.LabelFor(x => x.Phone)
            @Html.TextBoxFor(x => x.Phone)
            @*@Html.ValidationMessageFor(x => x.Phone)*@
        </div>
       
        <div>
            @Html.LabelFor(x => x.Subject)
            @Html.TextBoxFor(x => x.Subject)       
        </div>
       
        <div>
            @Html.LabelFor(x => x.Message)
            @Html.TextAreaFor(x => x.Message)
            @*@Html.ValidationMessageFor(x => x.Message)*@
        </div>
       
        @Html.HiddenFor(x => x.ThankYouPage)
       
        <input type="submit" value="Submit" />
      
    }

    CONTROLLER

    public class ContactSurfaceController : SurfaceController
        {
            [HttpPost]
            public ActionResult Contact(ContactModel model)

            {           
                if (ModelState.IsValid)
                {
                    var sb = new StringBuilder();

                    sb.AppendFormat("<p>Name: {0}</p>", model.Name);
                    sb.AppendFormat("<p>Email: {0}</p>", model.Email);
                    sb.AppendFormat("<p>Phone: {0}</p>", model.Phone);               
                    sb.AppendFormat("<p>Message: {0}</p>", model.Message);

                    library.SendMail("email from", "emails to send to as set in page property", model.Subject, sb.ToString(), true);                

                    return RedirectToUmbracoPage(model.ThankYouPage);               
                }
                return CurrentUmbracoPage();
            }

        }

     

Please Sign in or register to post replies

Write your reply to:

Draft