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>
Member
3 Points
9 Posts
Case statement help in Razor.
May 24, 2018 04:13 AM|cVishal259|LINK
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>
All-Star
194009 Points
28028 Posts
Moderator
Re: Case statement help in Razor.
May 24, 2018 07:17 AM|Mikesdotnetting|LINK
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>
}
Contributor
2096 Points
1040 Posts
Re: Case statement help in Razor.
May 24, 2018 09:31 AM|Khuram.Shahzad|LINK
Please check:
https://www.w3schools.com/asp/razor_cs_logic.asp
Member
3 Points
9 Posts
Re: Case statement help in Razor.
May 24, 2018 02:29 PM|cVishal259|LINK
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.
All-Star
52151 Points
23248 Posts
Re: Case statement help in Razor.
May 24, 2018 02:44 PM|mgebhard|LINK
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.
Razor Syntax reference.
https://docs.microsoft.com/en-us/aspnet/web-pages/overview/getting-started/introducing-razor-syntax-c
Member
3 Points
9 Posts
Re: Case statement help in Razor.
May 24, 2018 03:51 PM|cVishal259|LINK
Thank you...