ASP.NET 4.0 New Html.Encode Syntax

This post should probably be filed under 'problems that no one will actually need to Google' but here goes anyways.

Maybe I'm weird, but I tend to write server side blocks and bindings in ASP.NET like so...

<h1><% =this.Model.Title %></h1>
<span><% =this.Model.Posted.ToShortDateString() %></span>
<div><% =this.Model.Content %></div>

All of my equal and pound signs are placed directly next to the content being written -- not the actual server code block. No big deal right? Well... maybe not quite the case in the new ASP.NET...

I started using the new ASP.NET 4.0 stuff today... yeah, I wasn't much of an early adopter this time... the IDE turned me off too much.

Anyways, when I tried the new HTML encoding syntax I got the following message...

Invalid expression term ':'

Apparently, few people write their blocks the same as I do... After poking around for a moment I realized that the parser just simply did not like the colon to be anywhere else except for directly by the percent sign. So just remember...

<%: "OK!" %>
<% :"Crash!" %>

Also, if you do this in Visual Web Developer (Express) then you'll get the message 'BC30035: Syntax error.'... but it is the same problem...

May 11, 2010

ASP.NET 4.0 New Html.Encode Syntax

Post titled "ASP.NET 4.0 New Html.Encode Syntax"