Copied to clipboard

Flag this post as spam?

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


  • Martin 278 posts 662 karma points
    Oct 15, 2012 @ 16:04
    Martin
    0

    News to Razor - Contact Form Select Option

    Hi all,

    Im completely new to razor and have been looking at the Cultiv Razor Contact package.
    I dont fully grasp Razor, but I have managed to add a custom field and a select option to my contact form.

    Im looking for some help on an easier way to create a select option with values that could be used multiple times.

     

    Thanks

    Martin 

  • Peter Gregory 408 posts 1614 karma points MVP 3x admin c-trib
    Oct 16, 2012 @ 08:06
    Peter Gregory
    0

    Hi Martin

    Unfortunately we had to remove your comment on this topic as it caused an issue on the server for some reason (still under investigation).  Could you please send an email with the code you pasted into that comment to pg [at] umbraco.com so I can investigate the issue further. I will repost that code here if you have not solved your issue yet.  Sorry for the inconvenience.

    Peter Gregory
    Umbraco HQ 

  • Martin 278 posts 662 karma points
    Oct 16, 2012 @ 10:47
    Martin
    0

    Hi Peter, 

    Ive emailed yo the code that I had posted. If you didnt recieve it let me know and I'll send again.

    In the meantime, if anyone knows how to add a select option and mulitple checkbox to the basic Cultiv Razor Form, any help would be grateful.

    Thanks

     

    Martin

  • Kurt Emch 44 posts 85 karma points
    May 31, 2013 @ 22:07
    Kurt Emch
    0

    Martin did you ever figure this out? I've been at it for a while now and can't crack this code. Lots of stuff going on in here.

    I'm rendering options options like this:

    <select class="businesstype-req" name="businessType" id="businessType">
    @RenderOptionSet("Manufacturing", "manufacturing", "", "option")
    @RenderOptionSet("Finance", "financing", "", "option")
    </select> 
    @helper RenderOptionSet(string fieldLabel, string fieldName, string errorText, string className)
    {
        <option value="@fieldName">@fieldLabel</option> 
    }
    private static string GetMailContent(dynamic page, string mailIntroText)
    {
    var businesstype = HttpUtility.HtmlEncode(HttpContext.Current.Request["businesstype-req"]);

    formResults.Add("Business Type", businesstype);

    Boggling my mind. I'm not getting any errors, just can't get the VALUE from the SELECT to show up in the email.

  • Charles Afford 1163 posts 1709 karma points
    Jun 02, 2013 @ 20:35
    Charles Afford
    0

    How come the RenderOptionSet helper you are only passing in 3 parameters and not four.  RenderOptionSet requires 4?  They are not optional?  I am probably missing something here :/.  Charlie.

  • Kurt Emch 44 posts 85 karma points
    Jun 02, 2013 @ 23:15
    Kurt Emch
    0

    I could probably remove both the errorText and className parameters from that help because the options don't need either one of them. I looked at the other helpers he had in here as an example to make the options one.

    With those helpers, I can get a dropdown menu to appear on the page. I've just been spinning my wheels on how to get the value from the <select></select> to appear in the resulting email.

  • Andreas Iseli 150 posts 427 karma points
    Jun 03, 2013 @ 14:34
    Andreas Iseli
    0

    Do you have a form around it? If there is no form, no values will be posted back.

    If you work with your own surface controller, then you should have an appropriate method for the postback.

  • Kurt Emch 44 posts 85 karma points
    Jun 03, 2013 @ 14:43
    Kurt Emch
    0

    Yes, the form itself works, as in I can get an email from it. Name, email, message fields all go through. I'm puzzled on a dropdown list because this form provided only fields for a name, email, and message as defaults. Adding more text fields is easy. Adding different types of fields, i.e. checkbox, dropdown list, radio fields is more difficult.

    I'm not quite sure how to build the dropdown list into what's already going on with this file. But I am trying.

  • Andreas Iseli 150 posts 427 karma points
    Jun 03, 2013 @ 14:55
    Andreas Iseli
    0

    I'm not sure about how your code looks like now, but shouldn't you reference the postback value using the id instead of the class name?

    var businesstype =HttpUtility.HtmlEncode(HttpContext.Current.Request["businesstype"]);

    Anyway I always use a target (string) and a source model property (list) and then I'm rendering the dropdownlist using razor as the following:

    @Html.DropDownListFor(m => m.Target, Model.Sources)
  • Kurt Emch 44 posts 85 karma points
    Jun 04, 2013 @ 15:48
    Kurt Emch
    0

    Andreas, thanks for the help. @Hmtl.DropDownListFor is throwing me an excpetion. 

    'System.Web.WebPages.Html.HtmlHelper' does not contain a definition for 'DropDownListFor' and no extension method 'DropDownListFor' accepting a first argument of type 'System.Web.WebPages.Html.HtmlHelper' could be found (are you missing a using directive or an assembly reference?)    at System.Web.Compilation.AssemblyBuilder.Compile()'

    I've googled it and haven't really had any luck with it. I'm not giving up though. It's something I'd like to figure out.

Please Sign in or register to post replies

Write your reply to:

Draft