With ASP.NET’s view engine/template aspx/ashx pages the way to spit to screen seems to be:
<%= Person.Name %>
Which was fine with webforms as alot of model data was bound to controls programatically. But with MVC we are now using this syntax more oftern.
The issue I have with it is quite trivial, but annoying either way. This is that it seems to break up the mark up i.e.:
<% foreach(var Person in People) { %> <%= Person.Name %> <% } %>
That seems like alot of opening and closing tags to me!
Other view engines in the MVC contrib have a means of spitting to screen with out opening and closing the script tags using standard keyword such as ‘print, out, echo’ i.e. (brail example):
<% for element in list: output '<li>${element}</li>' end %>
Now, I said this may seem trivial, but it just seems more readable this way. So what are the advantages of MS having this syntax, and not providing a output method?
Cheers, Chris.
Consider something like this, instead:
I believe that’ll work. (Although I haven’t tested it; I’ve only just begun with MVC and don’t have the toolset here at the office.)
EDIT: I apparently missed the actual question … 🙂
Microsoft does provide an output method, but didn’t provide a syntax like the one you describe. The output method is
Response.Write(). I can’t answer this directly (I believe you’ll need to check with Scott Hanselmann over at MS :)), but I think they didn’t want to complicate scripting by adding yet-another-language for us to learn; I think they wanted to leverage the languages (C#, VB, etc.) which developers already knew.EDIT #2: I placed the following in a comment, and in retrospect (for completeness), it should be part of the answer.
If you head over to the Learn MVC site on ASP.NET, in the view tutorial (that’s the link), you’ll see the following paragraph:
Essentially,
<%= %>is the accepted shortcut forResponse.Write, and you therefore can use the fullResponse.Writemethod anywhere you’d use<%= %>.