views:

45

answers:

2

Why does my html helper extension work if I do:

<%= Html.MyExt() %>

all mvc helpers work like:

<% Html.TextBox(""); %>

My extension builds a StringBuilder, then returns a string.

+1  A: 

<%= command %> runs the command and prints the returned string. The command must return a string.

<% command; %> just runs the command. Anything returned by the command will be ignored.

Most HTML helpers I've seen use the first format.

Richard
+6  A: 

This helper must return string (ASP.NET MVC 1.0) or MvcHtmlString (ASP.NET MVC 2.0) which is written to the response stream (using Response.Write):

<%= Html.MyExt() %>

This helper returns nothing (void) it simply executes the extension method:

<% Html.TextBox(""); %>
Darin Dimitrov