Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
Hello everyone,
I am trying to edit the email Example-Template.cstml in \Views\Partials\Forms\Emails
I want to include an if-statement: only show field B if the value of field A = X.
(Disclaimer: I have never worked with Razor before; I am working only with what I see here.)
The code I included is:
<h2>Type of change:</h2> @Model.GetValue("mutation") @if (Model.GetValue("mutation") == "e-mailadress") { @Model.GetValue("old-email") }
But this doesn't work. The email does get sent. And in the email, it does show the value for "mutation":
Type of change: e-mailadress
But it ignores the if-statement.
I tried simplifying it to test if the if-statement worked at all:
<h2>Type of change:</h2> @Model.GetValue("mutation") @if (Model.GetValue("mutation") == "e-mailadress") { <p>Hello!</p> }
But it also ignores this. It seems the if-statement just doesn't work. Any ideas what I am doing wrong? I would think it should be possible to include or exclude fields with an if-statment.
Thanks,
Jeroen
Hi Jeroen,
Can you try this
@if (Model.GetValue("mutation").ToString() == "e-mailadress")
Maybe Model.GetValue does not return a string type but object. When rendering in razor it will do the .ToString() under the hood I think
Dave
Thanks this helped https://forpc.onl/bitlife-life-simulator-on-pc/
Hi Dave,
This works! Great, thanks.
I had been struggling with this for days. Great forum, this.
Thank, Jeroen
Hi Jeroen;
Glad to see the issue is solved. Don't forget to mark this topic as solved.
Hi everyone,
Please allow me to reply to this old thread. Unfortunately Dave's version doesn't work for me.
Now I would like to know, if this is an issue connected to the reply? My code would be:
@if (Model.GetValue("ibanswift").ToString() == "Yes / Ja") { (do something) }
Do I have to do something about the spaces within the answer?
Thanks!
Simeon
Hi Simeon,
What type of property editor are you using for "ibanswift" property ?
It's a single choice radio button (if you mean this).
Thanks! Simeon
I also tried this:
@{ string iban = Model.GetValue("ibanswift").ToString(); if (iban == "Yes / Ja") { (do something) }
But this also didn't work. Error message is "error CS1525: Invalid expression term '>'"
Thanks, Simeon
Please allow me to come back to this topic... I would be happy to get any hint...
Best, Simeon
I managed to solve this. This worked for me:
@if(@Model.DynamicFields.project.Contains("STC")) { (do something) }
is working on a reply...
Write your reply to:
Upload image
Image will be uploaded when post is submitted
Razor email-template: if-statement
Hello everyone,
I am trying to edit the email Example-Template.cstml in \Views\Partials\Forms\Emails
I want to include an if-statement: only show field B if the value of field A = X.
(Disclaimer: I have never worked with Razor before; I am working only with what I see here.)
The code I included is:
But this doesn't work. The email does get sent. And in the email, it does show the value for "mutation":
Type of change: e-mailadress
But it ignores the if-statement.
I tried simplifying it to test if the if-statement worked at all:
But it also ignores this. It seems the if-statement just doesn't work. Any ideas what I am doing wrong? I would think it should be possible to include or exclude fields with an if-statment.
Thanks,
Jeroen
Hi Jeroen,
Can you try this
Maybe Model.GetValue does not return a string type but object. When rendering in razor it will do the .ToString() under the hood I think
Dave
Thanks this helped https://forpc.onl/bitlife-life-simulator-on-pc/
Hi Dave,
This works! Great, thanks.
I had been struggling with this for days. Great forum, this.
Thank, Jeroen
Hi Jeroen;
Glad to see the issue is solved. Don't forget to mark this topic as solved.
Dave
Hi everyone,
Please allow me to reply to this old thread. Unfortunately Dave's version doesn't work for me.
Now I would like to know, if this is an issue connected to the reply? My code would be:
Do I have to do something about the spaces within the answer?
Thanks!
Simeon
Hi Simeon,
What type of property editor are you using for "ibanswift" property ?
Dave
Hi Dave,
It's a single choice radio button (if you mean this).
Thanks! Simeon
Hi everyone,
I also tried this:
But this also didn't work. Error message is "error CS1525: Invalid expression term '>'"
Thanks, Simeon
Hi Dave,
Please allow me to come back to this topic... I would be happy to get any hint...
Thanks!
Best, Simeon
Hi everyone,
I managed to solve this. This worked for me:
is working on a reply...