I am trying to use a ternary operator in Razor similar to this question , but what I want to infer contains spaces. This code
@(selectedGoal == null ? "" : "value=" + selectedGoal.Name)
should produce
value="Goal 3"
as the value of selectedGoal.Name is "Goal 3". Instead i get
value="Goal" 3
which is useless. I tried a bunch of different combinations of escaped quotes, @ characters and @ characters, and I just can't get this to work, i.e.
@(selectedGoal == null ? "" : "value=" + "selectedGoal.Name") @(selectedGoal == null ? "" : " value=@selectedGoal.Name ")
and then I just get something like
value="selectedGoal.Name"
Does anyone know how this should be done?
source share