what is the difference between <%: and <%= ?
相关问题
- How to dynamically load partial view Via jquery aj
- how to get full servername and port running in mvc
- Windows Shared hosting - custom scheduled task
- How to reference javascript file in ASP.NET MVC 2
- Should one try to guard against null reference exc
相关文章
- “Dynamic operations can only be performed in homog
- Forward request from servlet to jsp
- superclass mismatch for class CommentsController (
- play2 framework my template is not seen. : package
- Mocking HttpRequest and HttpResponse for MVC Appli
- How to catch exception in flutter?
- Undoing “Set as Start Page”
- mvc.net routing: routevalues in maproutes
Essentially, the
<%:
tag encodes any strings that haven't already been encoded. So:... is the same as:
But if you accidentally use the tag where it wasn't necessary:
... it will be the same as if you hadn't:
See http://weblogs.asp.net/scottgu/archive/2010/04/06/new-lt-gt-syntax-for-html-encoding-output-in-asp-net-4-and-asp-net-mvc-2.aspx for a full explanation.
The difference is that <%: automatically HTML encodes the string whereas <%= does not.
Back before MVC2 came out in order to HTML encode a string you had to use the Html.Encode() method inside the view.
However with MVC2 they added the <%: tag, which outputs the same thing but handles the HTML encoding for you.
As a rule of thumb you should always output your strings using the <%: tag, unless you have a good reason not to.
Checkout Scott Gu's blog for more information on the subject.