locked
Case statement help in Razor. RRS feed

  • Question

  • User-1590744680 posted

    Below is the razor code .. I'm trying to create an email based on non empty Location field.  if location is 'Not set'  in database then 

    search string should be  'Here are some countries that match your recent search'  --taking out 'for' from string

    if location is anything other than 'Not Set' then 

    search string should be 'Here are some countries that match your recent search for'  -- put back for. 

    <tr>
    <td>
    <table cellpadding="0" cellspacing="0" border="0" width="100%">
    <!-- F1 copy and button-->
    <tr>
    <td class="padt20 " align="center" style=" padding-top: 35px; padding-bottom: 5px;">
    <table class="90" cellpadding="0" cellspacing="0" border="0" width="85%">
    <tr>
    <td class="h3 padb10" style="text-align: center; color: #353e44; font-family: Helvetica, Arial, sans-serif, 'Roboto'; font-weight: 300; font-size: 28px; line-height: 38px; padding-
    </span></span>.</td>
    </tr>
    </table>
    </td>
    </tr>
    </table>
    </td>
    </tr>

    Thursday, May 24, 2018 4:13 AM

Answers

  • User-821857111 posted

    Here are some countries that match your recent search

    @if(!string.IsNullOrEmpty(Model.Locaton)){
    <text>for
    <span style="color:#353e44;">

    <span style="text-decoration:none;font-family:arial;font-style:normal;font-weight:bold;font-size:26.67px;color:#003399;">
    @Model.Location
    </span></span></text>
    }

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, May 24, 2018 7:17 AM
  • User475983607 posted

    There are several Razor syntax errors.  I believe I fixed the syntax errors.   However, there's still logical errors as the condition/else produces equal HTML.  IMHO, pass a model that reflects the expected resulting HTML rather than crafting logic in the View - if possible.

    <td class="h3 padb10" style="text-align: center; color: #353e44; font-family: Helvetica, Arial, sans-serif, 'Roboto'; font-weight: 300; font-size: 28px; line-height: 38px; padding-bottom: 5px;">
        @if (Model.InquiryListing_BaseLocation.ToLower() == "unknown")
        {
            <text>Here are some countries that match your recent search
                <span style="color:#353e44;">
                    <span style="text-decoration:none;font-family:arial;font-style:normal;font-weight:bold;font-size:26.67px;color:#003399;">
                        @Model.Location
                    </span>
                </span></text>
        }
        else
        {
    
            <text> Here are some countries that match your recent search in
                <span style="color:#353e44;">
                    <span style="text-decoration:none;font-family:arial;font-style:normal;font-weight:bold;font-size:26.67px;color:#003399;">
                        @Model.Location
                    </span>
                </span>
            </text>
    
        }
    </td>

    Razor Syntax reference.

    https://docs.microsoft.com/en-us/aspnet/web-pages/overview/getting-started/introducing-razor-syntax-c

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, May 24, 2018 2:44 PM

All replies

  • User-821857111 posted

    Here are some countries that match your recent search

    @if(!string.IsNullOrEmpty(Model.Locaton)){
    <text>for
    <span style="color:#353e44;">

    <span style="text-decoration:none;font-family:arial;font-style:normal;font-weight:bold;font-size:26.67px;color:#003399;">
    @Model.Location
    </span></span></text>
    }

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, May 24, 2018 7:17 AM
  • User-1780421697 posted

    Please check:

    https://www.w3schools.com/asp/razor_cs_logic.asp

    Thursday, May 24, 2018 9:31 AM
  • User-1590744680 posted

    Thank you for your answer.. I'm trying to modify expression and look for 'unknown' in location field rather than looking for non null fields..  

    something like: 


    <tr>
    <td>
    <table cellpadding="0" cellspacing="0" border="0" width="100%">
    <!-- F1 copy and button-->
    <tr>
    <td class="padt20 " align="center" style=" padding-top: 35px; padding-bottom: 5px;">
    <table class="90" cellpadding="0" cellspacing="0" border="0" width="85%">
    <tr>
    <td class="h3 padb10" style="text-align: center; color: #353e44; font-family: Helvetica, Arial, sans-serif, 'Roboto'; font-weight: 300; font-size: 28px; line-height: 38px; padding-bottom: 5px;">

    </span></span></text>
    }

    else {

    </span></span></text>

    }
    }
    .</td>
    </tr>
    </table>
    </td>
    </tr>
    </table>
    </td>
    </tr> 

    but this is giving error out. 

    Thursday, May 24, 2018 2:29 PM
  • User475983607 posted

    There are several Razor syntax errors.  I believe I fixed the syntax errors.   However, there's still logical errors as the condition/else produces equal HTML.  IMHO, pass a model that reflects the expected resulting HTML rather than crafting logic in the View - if possible.

    <td class="h3 padb10" style="text-align: center; color: #353e44; font-family: Helvetica, Arial, sans-serif, 'Roboto'; font-weight: 300; font-size: 28px; line-height: 38px; padding-bottom: 5px;">
        @if (Model.InquiryListing_BaseLocation.ToLower() == "unknown")
        {
            <text>Here are some countries that match your recent search
                <span style="color:#353e44;">
                    <span style="text-decoration:none;font-family:arial;font-style:normal;font-weight:bold;font-size:26.67px;color:#003399;">
                        @Model.Location
                    </span>
                </span></text>
        }
        else
        {
    
            <text> Here are some countries that match your recent search in
                <span style="color:#353e44;">
                    <span style="text-decoration:none;font-family:arial;font-style:normal;font-weight:bold;font-size:26.67px;color:#003399;">
                        @Model.Location
                    </span>
                </span>
            </text>
    
        }
    </td>

    Razor Syntax reference.

    https://docs.microsoft.com/en-us/aspnet/web-pages/overview/getting-started/introducing-razor-syntax-c

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, May 24, 2018 2:44 PM
  • User-1590744680 posted

    Thank you... 

    Thursday, May 24, 2018 3:51 PM