I suggest you ...

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?

106 votes
Vote
Sign in
Check!
(thinking…)
Reset
or sign in with
  • facebook
  • google
    Password icon
    I agree to the terms of service
    Signed in as (Sign out)
    You have left! (?) (thinking…)
    Chris HynesChris Hynes shared this idea  ·   ·  Flag idea as inappropriate…  ·  Admin →

    2 comments

    Sign in
    Check!
    (thinking…)
    Reset
    or sign in with
    • facebook
    • google
      Password icon
      I agree to the terms of service
      Signed in as (Sign out)
      Submitting...
      • PeterPeter commented  ·   ·  Flag as inappropriate

        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.

      Feedback and Knowledge Base