Alex Rivera | Logout

How to include JavaScript from a Partial View in ASP.NET MVC3

Asked 2011-01-16T20:54:32.387
30

I would like to be able to provide a way for partial views to include JavaScript code / files at the bottom of a view. This would enable partial views to include any JavaScript files that they depend on. For instance, if I wanted to write a partial that needs to create a JQueryUI dialog, I would like to import the JQueryUI JavaScript file as well as add JavaScript code that renders the dialog.

I'm currently writing this code in the parent view, which makes it kind of pointless to use a partial view.

I understand that calling RenderPartial multiple times would result in scripts being included multiple times. This is a solvable issue once I know how to actually include JavaScript into the main view from the partial view.

Edit
Report

1 Answer

0

You can include <script> tags inside the <body> tag so you can have them inside your partial view.

answered 2011-01-16T20:59:29.350

Your Answer