Wednesday, April 15, 2009

Quick ASP.NET MVC Tip: Double Check Html vs =Html

I keep running into this silly error in my ASP.NET views:

The best overloaded method match for 'System.IO.TextWriter.Write(char)' has some invalid arguments

The root cause always takes me a few minutes to realize, but has to do with HtmlHelper extension methods. Some return strings, as in <%=Html.TextBox(...)%>.  Others output directly to the page, as in <%Html.RenderPartial%>.  If you try to use the
"=" when it's not needed, you'll get the error above.  Just remove the "=" and it's fixed!

To explain furthur, every time you view a page in ASP.NET MVC or WebForms, ASP.NET compiles the markup into .NET code.  So <%=Html.TextBox(...)%> behind the scenes becomes something like output.Write(Html.TextBox(...)).  When you write <%=Html.RenderPartial(...)%>, behind the scenes, this becomes output.Write(Html.RenderPartial(...)).  Since Html.RenderPartial doesn't return a string, and the output.Write method is looking for a string, the application fails with the above error.

Monday, April 6, 2009

I'm Taking Classes at Stanford

When I entered college so many years ago, my advisor asked what I wanted to major in.  I had two things that interested me - computers and art.  I told my advisor this, and being that he was also the Fine Arts dean, I was signed up as an art major, with the understanding I'd take a few Computer Science courses and either minor or change my degree.  Four years of portfolios and studios and critiques later, I walked with a Bachelor of Art in Fine Art, yet gainfully employeed as a junior VB6 developer at a medium sized food-service company nearby. 

The CS classes had centered on Access and HTML, but I decided weren't worth minoring in.  Since then, I've managed to teach myself .NET on-the-job, plus using the wonderful online resources available, and get certified so that I have some sort of paper saying I can program.  I feel I have a pretty good CS foundation now, but I do wonder if I've missed some core principals by not having any traditional CS training.   So when I saw this Wired article about an iPhone App Development course being made available via iTunesU, I subscribed right away and started looking at other CS offerings.  

As I started digging, I was surprised by the amount of content available.  Several universities and even smaller colleges now offer a range of course video, audio, and materials online via iTunes for free via an initiative called iTunesU.  Obviously, this isn't the same as sitting in the class and getting graded (as the professors frequently point out to the students), but it is high quality instructional material that, with a little sticktoitiveness, can give you some knowledge about areas that interest you.

As a side-note, this is where Apple's focus on the infrastructure really pays off- I'm able to discover and play this content, and even download to my phone through a very polished consistent UI.  When Elizabeth recently went back for a nutrition major, the hoops you had to jump through to get crummy PDF slides off their intranet was less than inspiring.

At any rate, having watched my first iPhone App Development session, I'm pretty sure I'll keep subscribed to a couple of courses, if only to be able to casually drop the line "I'm taking a few Stanford courses on the side".

Wednesday, April 1, 2009

Windows Mobile Marketplace Video

iStartedSomething has a video of the new Windows Mobile Marketplace experience.  Looks pretty nice, and definitely something Windows Mobile needs.  This has been one of the more enjoyable aspects of the iPhone - I frequently browse and try apps from the phone without any messy download-and-sync installations.  Personally, I've never quite understood why .NET CF developers often don't make mobile cab installers - which are actually _easier_ to create than desktop installers.  I'll be interested to see what apps land on here, and may have to fire up a .NET CF project myself now!