Copied to clipboard

Flag this post as spam?

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


  • Jeric 122 posts 192 karma points
    Jan 24, 2013 @ 10:35
    Jeric
    0

    How to render the contour razor in a .cshtml file?

    I've tried searching the forum but had found nothing on the topic.

    I need to render the macro of a contour form in a .cshtml page.

    thanks

     

  • Comment author was deleted

    Jan 24, 2013 @ 10:40

    Hi Jeric,

    Is this in mvc rendering mode? Then you'll need the syntax described in this post http://umbraco.com/follow-us/blog-archive/2012/10/30/getting-started-with-mvc-in-umbraco-410.aspx

    So

    @Umbraco.RenderMacro("myMacroAlias", new{ name = "Ned", age = 28 })

    for a contour form this would be

    @Umbraco.RenderMacro("umbracoContour.RazorRenderForm", new{ FormGuid = "29e6a8df-71a2-45a0-aedd-9e0a114e87e2" })

    Of course you'll need to correct form guid, that can be found on the settings tab of the form 

    If you are in webforms rendering mode you should be able to just use the insert macro button from the toolbar

  • Jeric 122 posts 192 karma points
    Jan 24, 2013 @ 14:20
    Jeric
    0

    I have tried using the below in my .cshtml file by replacing the FormGuid with the contour form guid that I need.
    @Umbraco.RenderMacro("umbracoContour.RazorRenderForm", new{ FormGuid = "29e6a8df-71a2-45a0-aedd-9e0a114e87e2" }) 

    I've got the below error:
    error CS0234: The type or namespace name 'RenderMacro' does not exist in the namespace 'Umbraco' (are you missing an assembly reference?)

    Anything that I need to inherit before I can use the Umbraco.RenderMacro?

  • Comment author was deleted

    Jan 24, 2013 @ 14:29

    Are you running in mvc rendering mode? So you have views and not master pages?

  • Jeric 122 posts 192 karma points
    Jan 24, 2013 @ 14:41
    Jeric
    0

    nop. it's umbraco 4.9

    Just running web forms

  • Comment author was deleted

    Jan 24, 2013 @ 14:47

    Check the MvcRenderContourForm.cshtml think you can just copy the contents of that and set a fixed formguid

  • Jeric 122 posts 192 karma points
    Jan 24, 2013 @ 15:18
    Jeric
    0

    I have tried that yesterday with the following:

     

    @using Umbraco.Forms.Mvc.Bridge.Html;
    @inherits umbraco.MacroEngines.DynamicNodeContext

    @{

    string action = "ContourForm";
    string controller = "FormRender";
    string formtoken = "UmbracoContourForm";
    string formGuid = "875fd3fb-a67e-4c44-afb1-197e69afb42d";    

        @Html.RenderMvcAction(action, controller, formGuid, formtoken, (umbraco.MacroEngines.DynamicNode)Model, (System.Dynamic.DynamicObject)Parameter);

    }

     

    But had been told the below:
    Please provide a valid form Id

    I've got the formGuid from my contour form but not sure why that it is not working.

  • Comment author was deleted

    Jan 24, 2013 @ 16:04

    hmm that should work, will give it a test

  • Comment author was deleted

    Jan 24, 2013 @ 16:20

    Yeah get the same result

    It expect the formguid as a parameter, this should work:

    Use that snippet above (from MvcRenderContourForm.cshtml) 

     then add a parameter with alias FormGuid of type form picker to your macro using your cshtml

  • Jeric 122 posts 192 karma points
    Jan 28, 2013 @ 11:19
    Jeric
    0

    any example on how the below should look like?

    "then add a parameter with alias FormGuid of type form picker to your macro using your cshtml"

    I'm quite new in this Razor / c# thing in umbraco.
    Appreciate your help

    thanks 

  • Jeric 122 posts 192 karma points
    Jan 28, 2013 @ 11:52
    Jeric
    0

    Managed to get the parameter with alias FormGuid working. The form is loading too. Thanks

  • Comment author was deleted

    Jan 28, 2013 @ 12:19

    Great :)

  • Robert Hughes 87 posts 110 karma points
    Jan 29, 2013 @ 03:34
    Robert Hughes
    0

    Hi,

    Is there an example/documentation of a Contour form running in an MVC rendered page.

    I am using the RenderHelper from UmbracoHelper to render the RazorRenderForm but when I submit the form nothing happens.

    I would be keen to know exactly what steps I am missing out on to get my form to submit and validate properly. Am I missing an HttpModule or something?

    cheers,

    Robert

     

  • Comment author was deleted

    Jan 29, 2013 @ 08:05

    @Robert you'll need to render the macro details on the syntax here http://umbraco.com/follow-us/blog-archive/2012/10/30/getting-started-with-mvc-in-umbraco-410.aspx

  • Robert Hughes 87 posts 110 karma points
    Jan 29, 2013 @ 20:23
    Robert Hughes
    0

    I have the form rendering fine through the Macro - I am just wondering what I need to do to get the form to 'work' so to speak. The form renders with this form tag markup.

    <form action="" enctype="multipart/form-data" method="post">

    <input name="__RequestVerificationToken" type="hidden" value="o0sTV6MwU/P8+tJImqYaxD9QleYZ5zDfZAGyWiOHY5LqWcNjk7qSiY8P7ROl9PwbUhrAtAeNSOw/Ys+c+QiposoK6Ags+YdIiSDrTRS2QaXbRtO8L/kDdSMaRLTP32+Pj56209IhIc6XMVDfGd4U8b1RLwhCrU5Heo2hgzbhyOumCqlcswtjv76bniErw+dL"><input data-val="true" data-val-number="The field FormStep must be a number." data-val-required="The FormStep field is required." id="FormStep" name="FormStep" type="hidden" value="1"><input data-val="true" data-val-required="The FormId field is required." id="FormId" name="FormId" type="hidden" value="04ce3316-0d8d-4e86-9eae-efd605b0b3d8"><input id="RecordId" name="RecordId" type="hidden" value=""><input data-val="true" data-val-required="The SubmitHandled field is required." id="SubmitHandled" name="SubmitHandled" type="hidden" value="False">

    After doing a bit of debugging it seems when I submit the form I get an exception "A required anti-forgery token was not supplied or was invalid" here in the MvcRenderContourForm

        @Html.RenderMvcAction(action, controller, formGuid, formtoken, (umbraco.MacroEngines.DynamicNode)Model, (System.Dynamic.DynamicObject)Parameter);

    Any ideas?

    cheers,
    Robert

  • Robert Hughes 87 posts 110 karma points
    Jan 29, 2013 @ 21:35
    Robert Hughes
    0

    OK,

    Did some more digging. I think that Anti-forgery error was a bit of a red herring maybe as It was a first-chance exception.

    Debugging the Model in the umbraco/plugins/contour/Form.cshtml file I can see that after submitting my Model.SubmitHandled is false.

    Still no exception is raised or anything logged though.

     

     

  • Comment author was deleted

    Jan 30, 2013 @ 09:03

    Did you chance anything to the form views or are they just the default one? It should just work then...

  • Comment author was deleted

    Jan 30, 2013 @ 09:11

    Giving it a test now, reporting back with the different steps in a moment !

  • Robert Hughes 87 posts 110 karma points
    Jan 30, 2013 @ 09:14
    Robert Hughes
    0

    I haven't changed any of the umbraco razor files at all.

  • Comment author was deleted

    Jan 30, 2013 @ 09:16

    Ok creating a test setup now, will report back in a minute

  • Comment author was deleted

    Jan 30, 2013 @ 09:22

    Just tested and it worked fine...

    1)Install umbraco with render engine set to Mvc (installed 6.0.0 RC)

    2)Create a doctype with template

    3)Create a content doc using that doctype

    4)Install Contour

    5)Create a form (created from the contact form template)

    6)Populate the template with some simple html and insert the macro, looks like:

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage
    @{
        Layout = null;
    }
    
    <html>
        <head>
        </head>
        <body>
        @Umbraco.RenderMacro("umbracoContour.RazorRenderForm", new {FormGuid="6f2903fc-e27a-4d68-88d7-8d948746a6fe" })
        </body>
    </html>

    7) Going to frontend and submitting form

    8)Viewing entries in Contour backoffice

    All this worked fine...

    Maybe you have an issue on your template, could you test with a simple template like this to see if that works?

    Thanks,
    Tim 

  • Robert Hughes 87 posts 110 karma points
    Jan 30, 2013 @ 09:34
    Robert Hughes
    0

    Thanks Tim i will try it again tomorrow just with a blank site. I am using 4.11.3 though - should work for that right?

  • Comment author was deleted

    Jan 30, 2013 @ 11:30

    Yeah should also work 

  • Robert Hughes 87 posts 110 karma points
    Jan 31, 2013 @ 20:42
    Robert Hughes
    0

    Ok - looks like I am an idiot. I had a mix of 3.0.1 and 3.0.6 installed which was obviously causing a problem. I apologise for wasting your time Tim - thanks for looking into it anyway.

    Still brings up the issue of logging though - as my issue did not log a thing. I think this is mostly Umbraco's issue with the macro renderer not logging exceptions however. I think there is a feature request for this coming up  -hopefully in 6 with a decent loggin system we will see more logging creeping into the system.

  • Robert Hughes 87 posts 110 karma points
    Feb 10, 2013 @ 22:25
    Robert Hughes
    0

    OK,

    So my forms were working nicely with 3.0.6. 

    Just upgraded to 3.0.7 and suddenly

    Error loading MacroEngine script (file: MvcRenderContourForm.cshtml)

    Couldn't get any more information out of it than that sadly.

    Tried with a brand new installation of 4.11.4 as well to make sure it wasn't me doing something stupid again.

    Has 3.0.7 broken compatibility with 4.11.x?

    cheers,

    Robert


  • Comment author was deleted

    Feb 12, 2013 @ 10:17

    3.0.7 doesn't work with umb 4 it's for umb 6 sorry for the inconvience 

  • Robert Hughes 87 posts 110 karma points
    Feb 12, 2013 @ 20:57
    Robert Hughes
    0

    Oh right thanks - might want to advertise that though.

  • Martin Kerr 1 post 21 karma points
    Feb 13, 2013 @ 13:22
    Martin Kerr
    0

    Hi,

    i'm having the same issue as Jeric was, namely:

    "Please provide a valid form Id"

     

    ... i have the parameter field defined okay on my doc type with an alias of formGuid, i have my form set on the content node, and if i display the "formGuid" variable [as defined in the MVC example cshtml] prior to the RenderMvCAction the variable is correctly set to my form's GUID

    i'm running umbraco 4.7.2 / contour 3.0.0

    Jeric said he'd fixed it, but he didn't say how :)

     

    i see by reflection that this error is pushed out when the form is determined to be null, based on whether the form was loaded from FormStorage, but i can't see why it isn't...

     

    thanks!


     


     


     

     

  • QuasPie 25 posts 85 karma points
    May 10, 2013 @ 09:32
    QuasPie
    0

    @Martin Kerr and other potential troubleshooters having this problem in the future..

    In your code, change the string:

    string formGuid = "inset-id-here";

    to:

    string formGuid = Parameter.formGuid;

     And then add the macro parameter with the type formPicker and the name formGuid in the macro, NOT in the razor file.

    When this is done, just call your form GUID from your macro call, like:

     <?UMBRACO_MACRO macroAlias="yourMacro" formGuid="insert-id-here"></?UMBRACO_MACRO>
  • Jan Skovgaard 11280 posts 23678 karma points MVP 10x admin c-trib
    Jun 26, 2013 @ 11:21
    Jan Skovgaard
    0

    Hi all

    I have Umbraco 4.11 installed running webforms.

    I have just installed Contour 3.012.

    When I insert a form in the rich text editor (Razor version) I get the "please provide a valid form id" message when I want to view the rendered form on the webpage.

    I have tried reading through the above answers and I don't get what I should do to fix it. So could someone please tell me if this scenario is possible? And if so what should I specifically do in what file and how?

    Cheers,
    Jan 

  • Comment author was deleted

    Jun 26, 2013 @ 11:23

    Hey Jan does it work when you place it on a template, just as a test?

  • Comment author was deleted

    Jun 26, 2013 @ 11:24

    ANd yes it should be possible but looks like it's failing to pass the form id

  • Jan Skovgaard 11280 posts 23678 karma points MVP 10x admin c-trib
    Jun 26, 2013 @ 11:26
    Jan Skovgaard
    0

    Not sure how I would do that? Could you give me an example? :)

    /Jan

  • Comment author was deleted

    Jun 26, 2013 @ 11:28

    Well can you try to insert it on a template (just use the insert macro option) just to see if that works well 

  • QuasPie 25 posts 85 karma points
    Jun 26, 2013 @ 11:29
    QuasPie
    1

    Hi Jan, as written in my latest answer, you have to make the form id a parameter to the macro.

  • Comment author was deleted

    Jun 26, 2013 @ 11:31

    Ah yeah sounds like the macro wasn't created succesfully (so missing the form id param), check how to do this manually here http://our.umbraco.org/projects/umbraco-pro/contour/documentation/Installation/Manual (last part of the page)

  • Jan Skovgaard 11280 posts 23678 karma points MVP 10x admin c-trib
    Jun 26, 2013 @ 11:36
    Jan Skovgaard
    0

    The FormGuid parameter exists on the macro - otherwise I would not have been able to select the macro from within the rich text editor. According to the documenation that is the only parameter that should be added, right?

  • Comment author was deleted

    Jun 26, 2013 @ 11:37

    Yup that's the only one, did you try it on a template yet, does that work ?

  • Jan Skovgaard 11280 posts 23678 karma points MVP 10x admin c-trib
    Jun 26, 2013 @ 11:40
    Jan Skovgaard
    0

    Ok, not sure what I did...but now it works...? :)

    Case closed - will post if I at some point can recreate this again. Thanks for the help guys.

    /Jan

  • Comment author was deleted

    Jun 26, 2013 @ 11:53

    Yeah most have been an error in the form id somehow but glad it's working now :)

  • Mikkel Olsen 20 posts 94 karma points
    Jul 02, 2013 @ 08:53
    Mikkel Olsen
    3

    Im basically stuck on the same problem.. I cant load my Form in my cshtml file. I have tried the answers above - but it keeps saying "Provide a valid form id" - I really cant figure out whats the trouble here. I can easily insert it on the template as Tim mentioned - and by that it works, however it isnt suitable for my current project to call the macro directly on the template - as it contains a lot of markup which is spliited into differenct macros already :-)

     EDIT - i got it working by using the following in my cshtml file.

     @( Html.Raw(umbraco.library.RenderMacroContent("<?UMBRACO_MACRO formguid=\"6f2903fc-e27a-4d68-88d7-8d948746a6fe\" macroAlias=\"umbracoContour.RazorRenderForm\" ></?UMBRACO_MACRO>", Model.Id)))

    Cheers,

    Mikkel Toustrup

     

  • Comment author was deleted

    Jul 02, 2013 @ 11:33

    Ok glad you got it working Mikkel :)

  • James Billington 2 posts 22 karma points
    Jul 25, 2014 @ 14:01
    James Billington
    0

    Or you could do it something similar to this, I'm using latest version of Contour and Umbraco Version 6.2.0 with UsiteBuilder

    This is my Model

    [DocumentTypeProperty(
            UmbracoPropertyType.Other,
            OtherTypeName = "Form picker",
            Name = "Ice Form Builder",
            Description = "Create or select your Ice Form",
            Tab = Tabs.Content)]
        public virtual string addIceFormGuid { get; set; }
    

    This is my view...

    @inherits Vega.USiteBuilder.UmbracoTemplatePageBase<IceCMS.Models.ContentPage>
    enter code here
    @{
    Layout = "Master.cshtml";
    
    var currentpage = this.CurrentContent;
    
    var getFormGuid = this.CurrentContent.addIceFormGuid; // set Contour Guid if exists
    }
    
    @section FullBody
    {
    <div>
        @currentpage.BodyText
    
        @if (getFormGuid != null)
        {
             @Umbraco.RenderMacro("umbracoContour.RazorRenderForm", new { FormGuid = @getFormGuid })
        }
    
    
    
    </div>
    }
    

    Simple, this works really well for me :-)

Please Sign in or register to post replies

Write your reply to:

Draft