working in an Asp.Net MVC3 project, using razor engine, I found a situation that I don't know how to handle at best. In a view, I have the following situation:
@foreach (var item in Model.Items) {
Html.RenderAction("ActionName", new {param = item});
}
I think it's a very typical situation.
Now let's say that the html portion rendered need a couple of javascript files to work properly, and a css too. And also I want that the partialView of this action should be available in other views as well, one or more times.
The question is: where's the best place to put the references to external js and css? I'd say in the PartialView... but I can I avoid that calling n times RenderAction, doesn't put on the page n times the same script declaration? Moreover, said that the problem of repeating the js and css is solved, how should I bind this external resources with the view? Usually in my views I put the external resources in a dedicated section, that the layout page will render at the bottom of the page, for performance reason. Am I supposed to do the same with the partialView, assuming that the view who call it will have access to the scripts section? But in this way I bind the design of the reusable partialView to the hosting view structure: if so, shouldn't I just declare the scripts and css in the hosting view?
I'm pretty new to MVC and I'd like to know which approach do you use to solve this design issue.