Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In MVC, when do you use <%= %> and <% %>?

Tags:

asp.net-mvc

In asp.net mvc, when do we use:

and

Do we ever need to put a ; (colon) ?

like image 529
public static Avatar asked Nov 21 '08 03:11

public static


1 Answers

<%= %> renders the output (string) of the contained command to the response. <% %> wraps executable statements (logic) in the view to control what gets executed. You don't use semicolons in the <%= %> blocks, but may in the <% %> depending on what statements are included.

String rendering:

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

Code block:

<% Html.RenderPartial( "ViewName" ); %>

EDIT: Here's a link to the reference.

like image 194
tvanfosson Avatar answered Nov 11 '22 23:11

tvanfosson