Support registering Javascript and CSS into <head>
MVC is great for building straight pages, but the current design falls down for components. You can't build an HtmlHelper extension (or any other kind of extension) that renders a script/css into <head> based on the configuration options passed in.
This makes component development very difficult. This is one place ASP.NET webforms shines -- the ClientScriptManager (http://msdn.microsoft.com/en-us/library/system.web.ui.clientscriptmanager.aspx). Obviously, we don't need everything there. Just including a couple methods like RegisterClientScriptBlock and RegisterStartupScript would be huge.
You could actually build a component and/or HtmlHelper that would be a drop in, instead of having to do the HtmlHelper + adding 3 or 4 other blocks render statements around the page to add the supporting resources.
I realize that MVC is now built around a top down render model, so <head> is rendered before the HtmlHelper would even be hit. This makes it a bit difficult to implement a feature like this, but that is exactly why MS should do it. Some sort of head insertion filter after the fact, perhaps?

While the implementation is not nearly complete, you can see that we started this feature (currently called Resource Manager) in ASP.NET Web Pages 2 (and MVC 4) Developer Preview.
Our plan is to finish the design and implementation by RTW of Web Pages 2 and MVC 4.
1 comment
-
Peter commented
Perhaps splitting the view rendering into two steps: PreRender and the actual Render would work better. This would allow helpers to register the list of CSS / JS files to include. I would probably prefer to write my own "script manager" to allow me to include different versions for debug and release. Of course I wouldn't mind having a css/js manager built-in -- just in case it's flexible enough.