tags:

views:

105

answers:

5

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.

A: 
 <% If(a==b){%>
   <% = Html.Encode("output some text here");%>    
 <% }%>
Mouk
A: 

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<%
}
Jon Benedicto
I wanted to avoid a tag soup.
Pino
+5  A: 

<%= ... %> is just a shortcut for <% Response.Write(...); %>.

giorgian
+4  A: 
<% if(a==b) {
  Response.Write(Html.Encode("output some text here"));
}%>
Geoff
Why did I assume it would be differant to webforms *red face* ... thanks
Pino
+4  A: 

<%= a==b ? Html.Encode("output some text here") : string.Empty %>

Jace Rhea