Is there an easy way to render absolute URLs with Microsoft Web Optimization framework / script bundling?

后端 未结 1 1412
轻奢々
轻奢々 2021-01-04 18:38

I\'m trying to render a JavaScript bundle using Microsoft\'s Web Optimization framework, like this:

@Scripts.Render(\"~/assets/bundle.js\")

1条回答
  •  别那么骄傲
    2021-01-04 18:47

    One easy way is with Scripts.RenderFormat:

    @Scripts.RenderFormat("","~/assets/bundle.js")
    

    A way to get URL from request. Couldn't seem to use multiple parameters with the RenderFormat, so that's why it looks a little ugly:

     @Scripts.RenderFormat("", "~/assets/bundle.js")
    

    or better yet, centralize a function to get the correct path (using a fictional function):

    @Scripts.RenderFormat("", "~/assets/bundle.js")
    

    Also, you don't need the .js on the bundle:

    bundles.Add(new ScriptBundle("~/assets/bundle")
    

    0 讨论(0)
提交回复
热议问题