Copied to clipboard

Flag this post as spam?

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


  • Casper Andersen 126 posts 508 karma points
    Mar 08, 2015 @ 22:31
    Casper Andersen
    0

    Passing Model to from view to Controller in a special way

    I know the title might not say much, but basically what i want to do is. I have a controller that starts up like this.

    [HttpPost]
    public ActionResult HandleFormPost(ContactModel model, string EmailTo)

    and on my view page is calling the controller is called like this

    @Html.Action("Index", "ContactSurface", new {model = KART.Models.ContactModel,EmailTo = Umbraco.Field("emailTo") })

    I know it works without the EmailTo part so that i call the controller like this

    @Html.Action("Index", "ContactSurface")

    and the Controller looks like this:

    [HttpPost]
    public ActionResult HandleFormPost(ContactModel model)

    That works but not the first one, what am i doing wrong ?

  • Casper Andersen 126 posts 508 karma points
    Mar 09, 2015 @ 02:03
    Casper Andersen
    0

    srry forgot to add soemthing, @Html.Action("Index", "ContactSurface") calls 

     public ActionResult Index()

            {

                return PartialView("Contact", new ContactModel());

     

            }

    which is calls

    @model KART.Models.ContactModel


    @using (Html.BeginUmbracoForm<KART.Controllers.ContactSurfaceController>("HandleFormPost"))

    {

        <div id="kontakt_formular">

            @Html.TextBoxFor(x => x.Name, new { @class = "navn", placeholder = "NAVN" })

            @Html.TextBoxFor(x => x.EmailFrom, new { @class = "email", placeholder = "EMAIL" })

            <br />

            @Html.TextAreaFor(x => x.Message, new { @class = "besked", placeholder = "BESKED" })

            <button type="submit" id="contact_submit_button" class="Custom_button" style="width:100%; margin-top:0px;">SEND</button>

        </div>

     

    }

    i would like to be able to get my EmailTo from the view into the partiel view through these 2 controller action methods is there some way to do that or perhaps just get the emailTo directly inside

  • Casper Andersen 126 posts 508 karma points
    Mar 09, 2015 @ 03:00
    Casper Andersen
    100

    Nevermind i found out i can use this way to get a nodes property bu its alias like this

    var nodes = umbraco.uQuery.GetNodesByType("the nodes alias here");if(nodes.Any()){IPublishedContent node =Umbraco.TypedContent(nodes.First().Id); var EmailToSomeone = node.GetProperty("emailTo", true).Value.ToString();
     and then add it here
    string To = new MailAddress(EmailToSomeone, model.Name).ToString();}
Please Sign in or register to post replies

Write your reply to:

Draft