How can i set the text for a label in razor page using "if" condition?

Viewed 28

I have the following

<label for="source" class="col-md-2 control-label">SourceFolder</label>

I have a value in the javascript , filed is called eventtype. I am trying to do the following

<label for="source" class="col-md-2 control-label">eventtype == 2 ? SourceDirectory 
 :SourceFolder</label>

How can i do this using ternary operator ?

1 Answers

For eventtype is a js variable,you can only use if in js.Here is a demo:

<label id="myLable" for="source" class="col-md-2 control-label">SourceFolder</label>

js:

<script>
var eventtype=2;
$(function() {
            var data = eventtype == 2 ? "SourceDirectory" : "SourceFolder";
            document.getElementById("myLable").innerHTML = data;
        })
</script>
Related