开发者

Can you open a view in asp.net MVC that does not have the view engine's extension?

开发者 https://www.devze.com 2023-01-25 12:03 出处:网络
I want to include the code in a javascript file inside of my Asp.net MVC page view (the view is a javascript result as described here.I want to do this for consolidation reasons for my javascript, to

I want to include the code in a javascript file inside of my Asp.net MVC page view (the view is a javascript result as described here. I want to do this for consolidation reasons for my javascript, to lower the loading overhead of my complex GUI for my RIA, to make compression more efficient, and to make debugging easier.

The issue is that I am using the Ext designer to create my GUI. Every time my开发者_运维百科 project is exported it creates 2 .js files per class, and since my GUI is pretty complex I have quite a lot of .js files already.

So my idea to consolidate (at runtime) all the javascript files into one was to have my main JavaScriptViewResult Razor view contain Html.RenderPartial() view calls to the .js files.

However, if I call Html.RenderPartial("GUI/BaseLayout.js"), I get an exception because it tries to find "GUI/BaseLayout.js.cshtml".

Is there any way to force Asp.net MVC to not add the view engine's extension to the RenderPartial call, or is there a better way to concatenate all my .js files into one outputted script file?


You can try writing you own extension method for the HtmlHelper which reads in the .js files and concatenates them. But doing this per-request can be a bit costly.

A second choice is to use a tool like Chripy (chirpy.codeplex.com). This is a Visual Studio add-on (not a plugin, so it should work with Express editions). It is primarily meant for compiling .less files, but it can do a lot more. You can for example make a .chirp.config file that looks something like this:

<?xml version="1.0"?> 
<root>        
    <FileGroup Name="main.scripts.js"> 
        <Folder Path="/" Type="*.min.js" Minify="false"/> 
        <File Path="MicrosoftAjax.js" /> 
    </FileGroup> 
</root>

If you now put this in Scripts folder it will find all .min.js files and MicrosoftAjax.js file and add them together into main.scripts.js file. You would probably have to make it a bit more complex to handle all of your .js files, but at least they would be precompiled.

0

精彩评论

暂无评论...
验证码 换一张
取 消