开发者

HTML Encoding Blocks - Invalid expression term ':'

I'm developing a new ASP.NET MVC 2.0开发者_StackOverflow application and wanting to use the new ASP.NET 4 encoding blocks.

My View code contains <%: Model.ActivityName %> however Visual Studio is reporting:

Unexpected token

at the position of the : (colon). When I run the application I get the following compilation error:

Compiler Error Message: CS1525: Invalid expression term ':'

What am i missing?

Cheers for any help/advice.


This feature is new to ASP.Net 4.0, which is in turn new to Visual Studio 2010.

In earlier versions, you should write

<%= Html.Encode(Model.ActivityName) %>


Sounds like the target framework is not set to .NET Framework 4.0.

To do this, in the solution explorer, right click the project root and select properties in the context menu.

In the application tab you should see a drop down for Target Framework. Change this to .NET Framework 4.0.

Try and compile to see if the error goes away.


as has already been pointed out, you need to use the correct version of VS. if you can't and you need to change all of your code to use the Html.Encode method Phil Haack had a post about doing the opposite which might be useful.

Not that I have tied it, but the reverse search and replace in VS should be something like

\<\%:b*{[^%]*}:b*\%\>

replaced with

<%:= Html.Encode\( \1 \) %>

or something close to that. Like I say I've no IDE at the moment to test, so try it before you run it over your entire project.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜