是否可以在不使用ASP.NET MVC的情况下呈现CSS / Javascript包? [英] Is a way I can render CSS/Javascript bundles without using ASP.NET MVC?

查看:54
本文介绍了是否可以在不使用ASP.NET MVC的情况下呈现CSS / Javascript包?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的代码使用的唯一需要ASP.NET MVC的是:
$ b $

 <<<< HTML here>>> 
< body>
<<<一些HTML在这里>>>
@ Scripts.Render(〜/ bundles / jquery)
@ Scripts.Render(〜/ bundles / textview)
@ Scripts.Render(〜/ bundles / Angular )
@ Scripts.Render(〜/ bundles / AngularApp)
< / body>
< / html>

以下是我的BundleConfig.cs中的示例

  bundles.Add(新的StyleBundle(〜/ bundles / css).include(
〜/ Content / css / * .css
)) ;

在调试或发布中呈现CSS的能力非常好,但我想完全离开使用MVC和只使用和index.html页面和ASP.NET Web API。有没有一种方法可以在不使用控制器的情况下获得与渲染包类似的功能? 您可以做两件事:


  1. 您已经为这些软件包创建了一个虚拟路径,以便您可以在外部访问它们。您可以使用Razor视图引擎创建您的html页面,并通过这样做,获得Razor引擎的强度,例如捆绑包 - 您可以简单地创建一条路线,以帮助您通过单一操作来处理静态文件。

可以说路线是:

  routes.MapRoute(
name:HTMLViewRoute,
url:Htmls / {* pathInfo},
defaults:new {controller =HTMLFileRouting,action =ViewRoute}} );

在路径中输入pathinfo并找到html文件的路径(使用Server.MapPath)和返回View(filePath,null),因为您不需要任何模型。


The only thing that my code uses which requires ASP.NET MVC is:

<<< HTML here >>>
<body>
    <<< Some HTML here >>>
    @Scripts.Render("~/bundles/jquery")
    @Scripts.Render("~/bundles/textview")
    @Scripts.Render("~/bundles/Angular")
    @Scripts.Render("~/bundles/AngularApp")
</body>
</html>

Here's a sample from my BundleConfig.cs

    bundles.Add(new StyleBundle("~/bundles/css").Include(
       "~/Content/css/*.css"
    ));

The ability to render the CSS in debug or release is really good but I want to move completely away from using MVC and just use and index.html page and ASP.NET Web API. Is there a way that I can get similar functionality with rendering bundles without using a controller?

解决方案

You can do two things:

  1. You already create a virtual path to these bundles so you can access them externally.
  2. You can create your html pages using the Razor view engine, and by doing that, get the "strength" of the Razor engine for things like bundles - You simple create a route that will help you server your static files from a single action.

lets say the routing will be:

routes.MapRoute(
                name: "HTMLViewRoute",
                url: "Htmls/{*pathInfo}",
                defaults: new { controller = "HTMLFileRouting", action = "ViewRoute"});

In the route take the pathinfo and find the path to your html file(using Server.MapPath) and return View(filePath,null) since you need no model.

这篇关于是否可以在不使用ASP.NET MVC的情况下呈现CSS / Javascript包?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆