Reputation: 10216
I'm working on ASP.NET Web Pages (Razor) project. I want to display HTML
code if the condition is true but it's seems like the browser is showing it as Plain Text
instead of HTML
code.
Here is my HTML :
<li>@(active=="test" ? "<a href='?log' id='button'>TEST</a>" : "<a href='?test' id='button'>TEST</a>")</li>
I want if @(active=="test")
condition is true then my HTML
code change to another. Please help me to do this?
Upvotes: 0
Views: 1232
Reputation: 16348
You can also try this
<li>@Html.Raw(active=="test" ?"<a href='?log' id='button'>TEST</a>" : "<a href='?test' id='button'>TEST</a>")</li>
The point is Razor always encodes output, you need to tell it not to do it using Html.Raw() helper
Upvotes: 1
Reputation: 661
Try this approach:
@if(active=="test")
{
<a href='?log' id='button'>TEST</a>
}
else
{
<a href='?test' id='button'>TEST</a>
}
Upvotes: 1