I have a Dictionary which is populated with Key/Value pair data.
When the Key is found in the Dictionary, the corresponding Value is displayed.
In turn the Dictionary item is removed.
But when it is removed the return of True or False is being rendered to client side.
Here is cut down version of the code used to represent the issue:
@{
Dictionary<String, String> KeyValuePairList = new Dictionary<String, String>();
KeyValuePairList.Add("Key01", "Value01");
String TempValue = "";
}
<div>
@if (KeyValuePairList.TryGetValue("Key01", out TempValue)) {
@TempValue
@KeyValuePairList.Remove("Key01")
}
else {
@:Value0001
}
</div>
Here is the generated HTML:
<div>Value01True</div>
What I have tried:
Here are some of the ways I have tried.
@if...
@(KeyValuePairList.Remove("Key01"))
...
OR
@{
...
bool TempBool = false;
}
...
@if...
@(TempBool = KeyValuePairList.Remove("Key01"))
...
Same render:
<div>Value01True</div>
@if...
if (@KeyValuePairList.Remove("Key01")) { }
OR
@(KeyValuePairList.Remove("Key01")?"":"")
...
Desired render, but using additional if statement:
<div>Value01</div>
@if...
<!--
...
Generated html with comment of True, but does not display in final browser view:
<div>Value01<!--</div>
Now the question is, is how to stop the return value being rendered to the final HTML.
Is there a standard way/best practice way of doing it?
If you can point me to source material or a solution, that would be great.