ASP.NET/MVC: Inline Code

What am I doing wrong? Why is <%= this %>

n't it interpreted as C #?

Here's the code: Hosted by imgur.com

And this is what it does (note the Firebug display): Hosted by imgur.com

What do you think is going on? MVC newb here :(

And the static class of the site: Hosted by imgur.com

(If you don't see screenshots on the page, view the source and use URLs from tags <img>

.)

+2


a source to share


4 answers


<%: %>

starts with .NET v4



For pre-v4, it is equivalent to <%= Html.Encode(...) %>

+5


a source


The problem was that I was using <% =%> (or even <%:%>) in a tag that had runat = "sever".



+4


a source


Shouldn't it be <% %>

or <%= %>

for the shorthand Response.Write answer?

Here's an MSDN article on Inline Code Blocks .

+2


a source


This happens to me sometimes when embedding code inside html attributes. I have never documented the exact reason, but sometimes you can work around this by using single quotes rather than double quotes.

0


a source







All Articles