在什么换成MVC ClientScriptManager? [英] What replaced ClientScriptManager in MVC?

查看:477
本文介绍了在什么换成MVC ClientScriptManager?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我转换一个ASP.NET窗体应用程序(即我没有写)到MVC 3应用程序。该ClientScriptManager在旧的应用程序使用。 ClientScriptManager不MVC 3有哪些替代ClientScriptManager?我已经做了足够的阅读知道CSM事做在ASP.NET AJAX功能;它注册JS脚本和功能有点类似于EditorTemplates如何为套类似的控制工作套。我并不希望实现MVC中的CSM;我只是想知道什么样的实践微软把在渲染CSM过时的地方。

I'm converting an ASP.NET Forms app (that I didn't write) to an MVC 3 app. The ClientScriptManager is used in the old app. ClientScriptManager doesn't exist in MVC 3. What replaced ClientScriptManager? I've done enough reading to know that CSM has something to do with AJAX functionality in ASP.NET; it registers "sets" of js scripts and functions somewhat akin to how EditorTemplates work for sets of similar controls. I'm not necessarily looking to implement a CSM in MVC; I just want to know what practices Microsoft put in place that rendered CSM obsolete.

推荐答案

ASP.Net MVC的设计,让您完全控制HTML和JS,而不是框架呈现这些对你来说,与ASP.Net。所以,没有什么取代了ClientScriptManager。其结果是,这完全取决于你如何处理您的JS。

ASP.Net MVC was designed to give you complete control over the HTML and js, rather than having the framework render these for you, as with ASP.Net. So, nothing really "replaces" the ClientScriptManager. As a result, it is entirely up to you how you handle your js.

您可以做一些简单的像包括<脚本...> 标签来引用嵌入式脚本或JS文件在你的 _Layout.cshtml 文件,或者你可以使用某种形式的JavaScript装载机像 RequireJS 或拿出自己计划完全使用HTML辅助什么的。

You can do something simple like include <script ...> tags to reference inline script or js files in your _Layout.cshtml file, or you could use some sort of JavaScript Loader like RequireJS or come up with your own scheme entirely using "Html Helpers" or something.

MVC 4中引入的捆绑的概念,允许您定义的脚本集合的捆绑,并有自动MVC运行如下,当你在浏览这样引用它们把它们合并起来给你:

MVC 4 introduced the concept of bundling which lets you define collections of scripts as "bundles" and have MVC automatically minify and merge them together for you when you reference them in your Views like this :

@ Scripts.Render(〜/包/ jQuery的)

这篇关于在什么换成MVC ClientScriptManager?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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