Copied to clipboard

Flag this post as spam?

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


  • Matthew Jackson 17 posts 36 karma points
    Feb 27, 2015 @ 00:49
    Matthew Jackson
    0

    accessing parent property within partial view

    Hey guys, I have a property and partial view on a textpage I would like a property from the textpage within the partial view. Can I do this, will this break my MVC view model?

  • Matthew Jackson 17 posts 36 karma points
    Feb 27, 2015 @ 00:59
    Matthew Jackson
    0

    Basically I want to pre-populate a text area within a form on my partial with data from a rich text editor on the textpage. This is so the content is editable by the content managers.

    I hope this helps.

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Feb 27, 2015 @ 05:21
    Jan Skovgaard
    0

    Hi Matthew

    You should be able to do that by simply writing @Model.Content.GetPropertyValue("yourRteAlias"); in your partial view macro if you're using strongly typed for instance.

    Looking forward to hearing from you.

    /Jan

  • Matthew Jackson 17 posts 36 karma points
    Mar 06, 2015 @ 07:32
    Matthew Jackson
    0

    ok Jan,

    Just starting out with MVC but my first issue is I can pass page elements to my partials views like this. It works. but when I use partialviewmacros, in the hope of utilizing htmlactions within surface controllers to share model content between models it fails.

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage
    @{
        Layout = "Master.cshtml";
    }
    
        @*@Umbraco.RenderMacro("ContactForm", new ContactModel { ThankYouPage = Model.Content.GetPropertyValue<int>("thankYouPage"), Disclaimer = Model.Content.GetPropertyValue<string>("disclaimer") })*@
    
        @Html.Partial("ContactForm", new ContactModel { ThankYouPage = Model.Content.GetPropertyValue<int>("thankYouPage"), Disclaimer = Model.Content.GetPropertyValue<string>("disclaimer") })
    

    in the above code, you can see i have things wired up to use either partialViews or render view via a partialViewMacro. Both render however when utilising partialViewMacros it doesnt find the thankyoupage or disclaimer content from the page, therefore doesnt pass the required strings into the new object.

  • Matthew Jackson 17 posts 36 karma points
    Mar 06, 2015 @ 07:35
    Matthew Jackson
    0

    Here is a copy of my primary contactSurfaceController...on init of the form this should accept the newly created ContactModel object, as passed from the templatepage, where it gathers requiredPropertys (disclaimer and thankyoupage) from the content tree. Once it has these stored as temp within the ContactModel I can then manipulate content utitlizing DOM or Jquery on user input of form. My plan is to then create a new child disclaimer model which may be in a child relationship to the contactModel and pass the manipulated/updated contract/disclaimer into the database via petapoco/email from there. Hope I still have you ;)

    using System.Linq;
    using System.Web;
    using System.Web.Mvc;
    using Umbraco.Web.Mvc;
    using System.ComponentModel.DataAnnotations;
    using System.Text;
    using umbraco;
    using Kitetrippin.logic.Models;
    
    namespace Kitetrippin.logic.Controllers
    {
        public class ContactSurfaceController : SurfaceController
        {
    
    
            [ChildActionOnly]
            public ActionResult ContactForm(ContactModel model)
            {
                /*var model = new ContactModel();*/
    
    
                //Initialize model however you want
                /*model.FullName = "Enter your name";*/
    
                //In case you need to access the current node
                /*var currentNode = Umbraco.TypedContent(UmbracoContext.PageId.GetValueOrDefault());*/
    
                //In case you need to access the home node
                /*var home = currentNode.AncestorsOrSelf(0).First();*/
    
                return PartialView("ContactForm", model);
            }
    
            [HttpPost, ValidateInput(false)]
            public ActionResult Contact(Kitetrippin.logic.Models.ContactModel model)
            {
    
                if (ModelState.IsValid)
                {
                    /*ApplicationContext.DatabaseContext.Database.Save(new Contact());*/
    
                    //Create new Contact object
                    var contactToAdd = new Kitetrippin.logic.Pocos.Contact();
    
                    //Set values from view model & grab the current node ID
                    contactToAdd.ContactId = UmbracoContext.PageId.Value;
                    contactToAdd.FirstName = model.FirstName;
                    contactToAdd.NickName = model.NickName;
                    contactToAdd.LastName = model.LastName;
                    contactToAdd.Age = model.Age;
                    contactToAdd.Email = model.Email;
                    contactToAdd.Phone = model.Phone;
                    contactToAdd.Message = model.Message;
                    //tempdisclaimer only tempdata.
                    contactToAdd.Disclaimer = model.Disclaimer;
    
    
                    //Get the Umbraco db
                    var db = ApplicationContext.DatabaseContext.Database;
    
                    //Add the object to the DB
                    db.Insert(contactToAdd);
    
    
                    //create new contact registration email.
                    var sb = new StringBuilder();
                    sb.AppendFormat("<h1>Kitetrippin New Student Pre-registration</h1>", model.FirstName);
                    sb.AppendFormat("<p>First Name: {0}</p>", model.FirstName);
                    sb.AppendFormat("<p>Nick Name: {0}</p>", model.NickName);
                    sb.AppendFormat("<p>Last Name: {0}</p>", model.LastName);
                    sb.AppendFormat("<p>Age: {0}</p>", model.Age);
                    sb.AppendFormat("<p>Email: {0}</p>", model.Email);
                    sb.AppendFormat("<p>Phone: {0}</p>", model.Phone);
                    sb.AppendFormat("<p>{0}</p>", model.Message);
                    //tempdisclaimer only to database to change
                    sb.AppendFormat("{0}", model.Disclaimer);
    
    
                    library.SendMail("[email protected]","[email protected]","KiteTripping - new Student Contact Form",sb.ToString(),true);
    
                    /*return RedirectToUmbracoPage(model.ThankYouPage);*/
    
                    //See here - At this point, I can initialise a Disclaimer model
                    //pass disclamer template(prepropulated inline html) 
                    //from tempstore(contact model) into the newly created Disclaimer object.
                    var disc = new Kitetrippin.logic.Models.DisclaimerModel();
                    disc.disclaimer = model.Disclaimer;
                    //From here I can return a partial view, which renders using the macro :) avoiding templating issues with a normal view.
                    return PartialView("DisclaimerForm", disc);
    
                    /*return CurrentUmbracoPage();*/
                    /* alternative is inheriting from render model using DisclaimerImportModel approach.*/
    
    
    
    
                }
                return CurrentUmbracoPage();
    
    
            }
    
    
        }
    }
    
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.Mvc;
    using Umbraco.Web.Mvc;
    using System.ComponentModel.DataAnnotations;
    using System.Text;
    using umbraco;
    using Kitetrippin.logic.Models;
    
    namespace Kitetrippin.logic.Controllers
    {
        public class DisclaimerSurfaceController : SurfaceController
        {
    
    
    
            [ChildActionOnly]
            public ActionResult DisclaimerForm(DisclaimerModel model)
            {
                string temp = model.disclaimer;
                /*var model1 = new DisclaimerModel();*/
    
    
                //Initialize model however you want
                /*model.FullName = "Enter your name";*/
    
                //In case you need to access the current node
                /*var currentNode = Umbraco.TypedContent(UmbracoContext.PageId.GetValueOrDefault());*/
    
                //In case you need to access the home node
                /*var home = currentNode.AncestorsOrSelf(0).First();*/
    
                return PartialView("DisclaimerForm", model);
            }
    
    
    
    
            [HttpPost, ValidateInput(false)]
            public ActionResult SaveArticle(Kitetrippin.logic.Models.DisclaimerModel model)
            {
                if (ModelState.IsValid)
                {
    
                    //Perform some business logic here
                    //Save Title and Article Html in database.
    
                    //contactToAdd.Disclaimer = model.Disclaimer;
    
    
    
                    return Json(new { IsOK = true });
                }
    
                return Json(new { IsOK = true });
            }
    
    
        }
    }
    
  • Matthew Jackson 17 posts 36 karma points
    Mar 06, 2015 @ 07:39
    Matthew Jackson
    0

    Here is a copy of the form/s and a little glue to make things more clear

    $(window).load(function () {
        renderName('FirstName');
        renderName('LastName');
    });
    
    
    $("#btnSubmit").on("click", function () {
        $("#htmlTextHolder").html($("#disclaimer").html());
        $("form#frmNewArticle").submit();
    });
    
    
        $("form#frmNewArticle").submit(function () {
        $.post($(this).attr("action"), $(this).serialize(), function (data) {
            if (!data.IsOK) {
                // in the case of an error, just display info about it to the user
            }
            else {
                // if the post went well, go back to the article listing
                //window.location.href = 'http://google.com.au'
            }
            return;
        });
        return false;
    });
    
    /*author
     **triggered when input feild onchanged, passes contents to all matching spans in disclaimer content.
     **used for dynamic population of disclaimer contract.
     */
    function renderName(inputname) {
    
        var elements = document.getElementsByName(inputname+"Placeholder");
    
        var i = 0;
        /*Must convert to array first to avoid looping dom elements of same name {*/
        elements = Array.prototype.slice.call(elements); //convert to array
        for (var i = 0; i < elements.length; i++) {
            var oldSpan = elements[i];
            var newSpan = document.createElement("span");
            newSpan.style.fontWeight = 'bold';
            newSpan.setAttribute("name", (inputname + "Placeholder"));
            newSpan.innerHTML = document.getElementById(inputname).value;
            oldSpan.parentNode.replaceChild(newSpan, oldSpan);
        }
    }
    
    
    
    @model Kitetrippin.logic.Models.ContactModel
    
    @using (Html.BeginUmbracoForm("Contact", "ContactSurface", null, new { @class = "contact-form" }))
    {
    
        <br />
        <h1>Learn to Kite</h1>
        <hr />
        @Html.ValidationSummary(true)
        <div>
            @Html.LabelFor(x => x.FirstName)
            @Html.DescriptionFor(x => x.FirstName)
            @Html.TextBoxFor(x => x.FirstName, new { name = "FirstName", onchange = "renderName('FirstName')", autofocus = "autofocus" })
            @Html.ValidationMessageFor(x => x.FirstName)
        </div>
        <div>
            @Html.LabelFor(x => x.NickName)
            @Html.DescriptionFor(x => x.NickName)
            @Html.TextBoxFor(x => x.NickName)
            @Html.ValidationMessageFor(x => x.NickName)
        </div>
        <div>
            @Html.LabelFor(x => x.LastName)
            @Html.DescriptionFor(x => x.LastName)
            @Html.TextBoxFor(x => x.LastName, new { name = "LastName", onchange = "renderName('LastName')" })
            @Html.ValidationMessageFor(x => x.LastName)
        </div>
        <div>
            @Html.LabelFor(x => x.Age)
            @Html.DescriptionFor(x => x.Age)
            @Html.TextBoxFor(x => x.Age)
            @Html.ValidationMessageFor(x => x.Age)
        </div>
        <div>
            @Html.LabelFor(x => x.Email)
            @Html.DescriptionFor(x => x.Email)
            @Html.TextBoxFor(model => model.Email, new { title = ModelMetadata.FromLambdaExpression(model => model.Email, ViewData).Description })
            @*@Html.TextBoxFor(x => x.Email, new { required = "required", autofocus = "autofocus", placeholder = "ex. [email protected]" })*@
            @Html.ValidationMessageFor(x => x.Email)
        </div>
        <div>
            @Html.LabelFor(x => x.Phone)
            @Html.DescriptionFor(x => x.Phone)
            @Html.TextBoxFor(x => x.Phone)
            @Html.ValidationMessageFor(x => x.Phone)
        </div>
        <div>
            @Html.LabelFor(x => x.CompetentSwimmer)
            @Html.DescriptionFor(x => x.CompetentSwimmer)
            @Html.CheckBoxFor(x => x.CompetentSwimmer)
            @Html.ValidationMessageFor(x => x.CompetentSwimmer)
        </div>
    
        <div>
            @Html.LabelFor(x => x.Message)
            @Html.DescriptionFor(x => x.Message)
            @Html.TextAreaFor(x => x.Message)
            @Html.ValidationMessageFor(x => x.Message)
        </div>
    
        @Html.HiddenFor(x => x.ThankYouPage)
        <input type="Submit" value="Submit" class="btn" />
        /*@Html.ContractDataFor(x => x.Disclaimer)*/
        /*Model.Disclaimer1 = MvcHtmlString.Create(Model.Disclaimer);*/
        @Html.HiddenFor(x => x.Disclaimer)
    }
    
Please Sign in or register to post replies

Write your reply to:

Draft