views:

105

answers:

2

Hi,

I was programming in Zend Framework and now I am also using ASP.NET MVC.

What I liked in Zend Framework is that the layout (something like Master page in ASP.NET world) is rendered AFTER the main content, so you can use html helper to insert javascript or require some css/js files while generating the main content and than the html helper will place all necessary code in head tag which is usually placed in layout (Master page). Is something like that possible in ASP.NET MVC?

+1  A: 

If I understand what you are asking correctly, you can put a content placeholder within the head tag on the master page. This lets you inject anything you like from your content pages.

Garry Shutler
Yes that is true, but imagine you would want to render UserControls on your page and each requires some piece of css or js, than you cannot access the "head" placeholder from them or am I missing something?
Steve
Without knowing your precise context, if you know you are putting a certain control on a page you can include the javascript and CSS required for the control through the page rather than the user control.For me, these often aren't separate files anyway as it is quicker for the browser to download few large files than several smaller ones, so it's a bit of a non-issue.
Garry Shutler
Also agree, I know that there ase these possibilities, but I liked the concept of ZF. Other example: the UserControls may generate this javascript dynamically or the imaginary site is complex portal with lots of widgets that are rendered using UserControl dynamically according to user settings. (Of course you can have one big javascript file with all script)
Steve
A: 

You can use the ScriptManager and ScriptManagerProxy controls with the Page.ClientScript property to organize client script on your site.

Scott Hanselman's recent blog post outlines some interesting ways to combine scripts for performance.

Josef