Copied to clipboard

Flag this post as spam?

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


  • Alan Johnstone 10 posts 101 karma points
    Feb 07, 2018 @ 14:40
    Alan Johnstone
    0

    Using BeginUmbracoForm with Related Links

    Hi Please bear with me I've literlay just got started with Umbraco. I have a client who wants to be able to create their own survey type content which flows depending on the answers. I am trying using a document with a RelatedLinks2 property and the below code in the template @inherits Umbraco.Web.Mvc.UmbracoTemplatePage @using Umbraco.Web.Models @{ var typedRelatedLinksConverted = Model.Content.GetPropertyValue

    if (typedRelatedLinksConverted.Any())
    {
        <ul>
            @foreach (var item in typedRelatedLinksConverted)
            {
                var linkTarget = (item.NewWindow) ? "_blank" : null;
            <li>
                <a href="@item.Link" target="@linkTarget">@item.Caption</a>
                    <input type="submit" name="submitButton" value="@item.Caption" />
            </li>
            }
        </ul>
    }
    

    This works as expected. I have a very simple Model

    public class Test1Model { public int Id { get; set; } public string TestText { get; set; } }

    I simple surface controller

    public class Test1SurfaceController : SurfaceController
    {
        public ActionResult HandleFormPost(string submitButton, Test1Model pqm)
        {
            string ss = submitButton;
            return RedirectToCurrentUmbracoPage();
        }
    }
    

    I can create a content page with multiple submit buttons posting to HandleFormPost and it works as expected. (not concerned about the redirect at the moment, think I can get that) My problem comes when I try and nest the Model.Content.GetPropertyValue RelatedLinks inside the @inherits Umbraco.Web.Mvc.UmbracoViewPage

    @using (Html.BeginUmbracoForm

    I have tried various combinations of partial views to try and allow use of both UmbracoTemplatePage to allow use of Model.Content and UmbracoViewPage to give access to the Model.

    Any help would be much appreciated - thanks Alan

  • Nigel Wilson 944 posts 2076 karma points
    Feb 07, 2018 @ 17:00
    Nigel Wilson
    0

    Hi Alan

    Going on a bit of a tangent here, but is your client wanting the answers saved, or is it simply more a "pathway" of pages depending on answers ?

    Cheers, Nigel

  • Alan Johnstone 10 posts 101 karma points
    Feb 07, 2018 @ 17:07
    Alan Johnstone
    0

    Hi Nigel

    Yes, plan is to save answers and route taken, think I can figure those bits out. Any help appreciated, cheers Alan

  • Nigel Wilson 944 posts 2076 karma points
    Feb 07, 2018 @ 18:01
    Nigel Wilson
    0

    Hi Alan

    All good - sorry I should have included this before before but was heading out the door to work.

    I started having a play with a fullpage.js to create a type of anonymous survey providing pathways depending on answers. The bones of this can be seen on the link below

    http://optimised.net.nz/quiz/

    But given you wish to record answers it probably isn't suitable.

    So with respect to your issue - are you saying you are looping through the related links within the beginform tag - should this be the other way round so as to create multiple forms on the page ?

    Cheers, Nigel

Please Sign in or register to post replies

Write your reply to:

Draft