Copied to clipboard

Flag this post as spam?

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


  • Brad 14 posts 105 karma points
    Nov 30, 2017 @ 23:20
    Brad
    0

    Switch inside of a foreach loop

    Why does this break?

        <table align="center" class="container" style="font-size: 14px; padding: 15px;">
            @foreach (var field in Model.Fields)
            {
                <tr class="row">
                    <td class="large-12" style=" padding:10px; font-weight:300; border-bottom: 1px solid #ccc;">@field.Name</td>
                    @{
                    switch(field.FieldType)
                    {
                        case "FieldType.FileUpload.cshtml":
                        {
                            <td class="large-12"style=" padding:10px; font-weight:300;  border-bottom: 1px solid #ccc;"><a href="@(siteDomain/@field.GetValue())" target="_blank" style="color: #00AEA2;">@field.GetValue()</a></td>
                         }
                            break;
    
                        case "FieldType.DatePicker.cshtml":
                        {
                            <td class="large-12" style=" padding:10px; font-weight:300; border-bottom: 1px solid #ccc;">@(Convert.ToDateTime(field.GetValue()).ToString("MMMM d, yyyy"))</td>
                        }
                        break;
    
                        case "FieldType.CheckboxList.cshtml":
                        {
                            <td class="large-12" style=" padding:10px; font-weight:300; border-bottom: 1px solid #ccc;">
                                @foreach (var color in field.GetValues())
                                {
                                    @color<br/>
                                }
                            </td>
                         }
                         break;
                        default:
                        {
                            <td class="large-12" style=" padding:10px; font-weight:300; border-bottom: 1px solid #ccc;">@field.GetValue()</td>
                        }
                         break;
                    }
                   } 
                </tr>
            }
    
        </table>
    
  • Alex Skrypnyk 6163 posts 24143 karma points MVP 8x admin c-trib
    Nov 30, 2017 @ 23:22
    Alex Skrypnyk
    0

    Hi Brad

    It's hard to say why exactly it's braking, can you show all razor code?

    What line is braking?

    Thanks,

    Alex

  • Brad 14 posts 105 karma points
    Nov 30, 2017 @ 23:25
    Brad
    0

    I'm trying to modify an email template for a form, but it doesn't seem to agree with the switch portion. If I take it out, the email goes through when I test the form. But when I put it back in, the email doesn't come through. Maybe it's something else??

    <body style="background-color: #f4f4f4; margin: 0 !important; padding: 0 !important;">
        <table align="center" class="container" style="font-size: 14px; padding: 15px;">
            @foreach (var field in Model.Fields)
            {
                <tr class="row">
                    <td class="large-12" style=" padding:10px; font-weight:300; border-bottom: 1px solid #ccc;">@field.Name</td>
    
                    switch(field.FieldType)
                    {
                        case "FieldType.FileUpload.cshtml":
                        {
                            <td class="large-12"style=" padding:10px; font-weight:300;  border-bottom: 1px solid #ccc;"><a href="@(siteDomain/@field.GetValue())" target="_blank" style="color: #00AEA2;">@field.GetValue()</a></td>
                         }
                            break;
    
                        case "FieldType.DatePicker.cshtml":
                        {
                            <td class="large-12" style=" padding:10px; font-weight:300; border-bottom: 1px solid #ccc;">@(Convert.ToDateTime(field.GetValue()).ToString("MMMM d, yyyy"))</td>
                        }
                        break;
    
                        case "FieldType.CheckboxList.cshtml":
                        {
                            <td class="large-12" style=" padding:10px; font-weight:300; border-bottom: 1px solid #ccc;">
                                foreach (var color in field.GetValues())
                                {
                                    @color<br/>
                                }
                            </td>
                         }
                         break;
                        default:
                        {
                            <td class="large-12" style=" padding:10px; font-weight:300; border-bottom: 1px solid #ccc;">@field.GetValue()</td>
                        }
                         break;
                    }
    
                </tr>
            }
    
        </table>
    

  • Nigel Wilson 945 posts 2077 karma points
    Nov 30, 2017 @ 23:38
    Nigel Wilson
    100

    Hi Brad

    Are you not able to debug in Visual Studio ?

    One thought is that a date is not set (null) and so breaks when in the case for datepicker - have no idea if this is or is not possible, just a thought.

    Cheers Nigel

  • Ben Palmer 180 posts 866 karma points c-trib
    Dec 01, 2017 @ 08:33
    Ben Palmer
    0

    Hi Brad,

    Check your error log found in the ~/App_Data/Logs folder and post any errors you get related to this here. It should tell us/you exactly what's going wrong.

  • Matthew Wise 271 posts 1373 karma points MVP 5x c-trib
    Dec 01, 2017 @ 08:57
    Matthew Wise
    0

    Probably not a full fix but the foreach is missing an @ in this section

    case "FieldType.CheckboxList.cshtml":
                    {
                        <td class="large-12" style=" padding:10px; font-weight:300; border-bottom: 1px solid #ccc;">
                            foreach (var color in field.GetValues())
                            {
                                @color<br/>
                            }
                        </td>
                     }
    
  • Brad 14 posts 105 karma points
    Jan 05, 2018 @ 21:24
    Brad
    0

    Thanks for the responses guys! I was away for a while so I wasn't able to repsond.

    It appears the datepicker issue that Nigel mentioned was the issue.

Please Sign in or register to post replies

Write your reply to:

Draft