In asp.net mvc 2 view i am trying to render something if true.
In code below i am trying to use Html.Encode(x) to render value into page but it does render nothing. What is wrong with if statement with html.encode?
Works
<%if (!ViewData.ContainsKey("DisplayQtyPrice")) {%>
<%: entry.Amount %>
<%}%>
Does not work
<%if (!ViewData.ContainsKey("DisplayQtyPrice")) {
Html.Encode(entry.Amount);
}%>
The problem is that you’re not actually adding anything to the response stream. There’s nothing wrong with Html.Encode, but you need to do something like this:
EDIT: That said, I think your first version is better, unless you have a problem with angle brackets 🙂