4
public class BundleConfig
{
    // For more information on Bundling, visit http://go.microsoft.com/fwlink/?LinkId=254725
    public static void RegisterBundles(BundleCollection bundles)
    {
        bundles.Add(new ScriptBundle("~/bundles/require").Include(
                        "~/Scripts/require.js"));
       ....

and in the _Layout.cshtml

@Scripts.Render("~/bundles/require")

it renders into (with EnableOptimizations = false):

<script src="/Scripts/require.js"></script>

but I want to add an attribute

<script src="/Scripts/require.js" data-main="/Scripts/main"></script>

how could I do that?

iLemming
  • 34,477
  • 60
  • 195
  • 309
  • I heard some MVC's alpha update adds RenderFormat method, but I'd rather find another way, if there's any – iLemming Mar 20 '13 at 17:28

2 Answers2

2

I've solved similar issue by configuring requirejs without data-main attribute. So, at first I had following code:

<script src="app/rconfig.js"></script>
<script src="plugin/requirejs/require.js" data-main="app/main.js"></script>

Next, let's get rid from the data-main attribute:

<script src="app/rconfig.js"></script>
<script src="plugin/requirejs/require.js"></script>
<script>
    require.config({
        baseUrl: "app"
    });
    require(['app/main.js']);
</script>

Next, I've put last 'script' content to the file:

<script src="app/rconfig.js"></script>
<script src="plugin/requirejs/require.js"></script>
<script src="app/rdatamain.js"></script>

At finish, I've put these three files to the bundle

omikad
  • 979
  • 8
  • 10
1

If you don't like RenderFormat, you can change the DefaultTagFormat globally on the ScriptsHelper too, but this attribute would now show up everywhere you called Scripts.Render

David Gardiner
  • 16,892
  • 20
  • 80
  • 117
Hao Kung
  • 28,040
  • 6
  • 84
  • 93