Reputation: 18586
In ASP.NET MVC, if I have some content on the page I can do the following:
<%=Html.ActionLink(..Blah Blah..)%>
How can I acheive the same result in the following block:
if(a==b)
{
Html.Encode("output some text here");
}
I want to do this without a lot of tags, hence why I am asking.
Upvotes: 0
Views: 2004
Reputation: 5018
<%= a==b ? Html.Encode("output some text here") : string.Empty %>
Upvotes: 4
Reputation: 1468
in MVC 4, simply use the following:
@if (x == y)
{
@Html.Encode('This is Just text')
}
Upvotes: 0
Reputation: 4746
<% if(a==b) {
Response.Write(Html.Encode("output some text here"));
}%>
Upvotes: 4
Reputation: 10582
To do this, you need to "drop" out of code and into the markup by closing the code with %> and then restarting the code block after your text with <%
For example:
if (a == b)
{
%>output some text here<%
}
Upvotes: 0