javascript 如何在 ASP.Net MVC 中使用 Backbone.js?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8662171/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 04:09:24  来源:igfitidea点击:

How can I use Backbone.js with ASP.Net MVC?

javascriptjqueryasp.net-mvcrestbackbone.js

提问by one.beat.consumer

I'm preparing to implement a Backbone.js UI (client-side MVC) within ASP.Net MVC 3+ web application (server-side MVC).

我准备在 ASP.Net MVC 3+ Web 应用程序(服务器端 MVC)中实现 Backbone.js UI(客户端 MVC)。

I've read plenty of Backbone tutorials, but none that illustrate how the technology may or may not be useful in an ASP.Net MVC scenario.

我已经阅读了大量的 Backbone 教程,但没有一个说明该技术在 ASP.Net MVC 场景中可能有用,也可能没有用。

What strategy should I follow when combining these two pieces?

结合这两个部分时应该遵循什么策略?

回答by TYRONEMICHAEL

To be fair, Backbone.js (client application) and MVC (server application) should have nothing in common. The only thing Backbone.js requires is a Restful Api. So what I would do is take a look at MVC 4's Web Api (Example). There are quite a few tutorials on the subject, but the one I listed gives quite a good overview.

公平地说,Backbone.js(客户端应用程序)和 MVC(服务器应用程序)应该没有任何共同之处。Backbone.js 唯一需要的是一个 Restful Api。所以我要做的是看看 MVC 4 的 Web Api(示例)。关于这个主题有很多教程,但我列出的教程给出了很好的概述。

Once you understand how to implement a Restful API, look at any tutorial on backbone.js that integrates with a server application. Just substitute your api with the tutorial's api and you should be in business. Read this book, it is priceless and contains brilliant examples on how to implement a backbone.js application locally and with a server.

一旦您了解了如何实现 Restful API,请查看有关与服务器应用程序集成的 Backbone.js 的任何教程。只需将您的 api 替换为教程的 api 即可,您应该可以开展业务了。阅读这本书,它是无价的,并且包含有关如何在本地和服务器上实现backbone.js 应用程序的精彩示例。

On a side note, MVC 4's Web API integrates perfectly with backbone. Have a look at a plugin developed by Addy Osmani, Backbone.Paginator. It helps make filtering, pagination, skip, sort etc extremely easy with MVC 4's Web API and odata filters.

附带说明一下,MVC 4 的 Web API 与主干完美集成。看看由 Addy Osmani 开发的插件Backbone.Paginator。它有助于使用 MVC 4 的 Web API 和 odata 过滤器使过滤、分页、跳过、排序等变得非常容易。

回答by Andrew

After learning Backbone.js and using it on a few projects, I've found that most of my time is spent figuring out how to use it, and not what my backend is doing. In terms of ASPMVC, you setup a few controller actions that return JSON.

在学习了 Backbone.js 并在一些项目中使用它之后,我发现我的大部分时间都花在弄清楚如何使用它上,而不是我的后端在做什么。就 ASPMVC 而言,您设置了一些返回 JSON 的控制器操作。

Rob Connery uses Backbone.js with MVC3 in his series Real-World ASP.NET MVC3on Tekpub.

Rob Connery 在他的Tekpub 上的Real-World ASP.NET MVC3系列中使用 Backbone.js 和 MVC3 。

Episode 6 - BackboneJS - is spent entirely introducing you to backbone and ASPMVC3 integration. Unfortunately, you must purchase the entire series for $32 and it helps to watch the whole thing to get a sense for whats being built. Further, I don't agree with the way he approaches everything in the videos but his use and description of Backbone.js is very helpful if you are new.

第 6 集 - BackboneJS - 完全向您介绍了主干和 ASPMVC3 集成。不幸的是,您必须以 32 美元的价格购买整个系列,这有助于观看整个过程以了解正在构建的内容。此外,我不同意他处理视频中所有内容的方式,但如果您是新手,他对 Backbone.js 的使用和描述非常有帮助。

DocumentCloud (the project from which Backbone.js emerged) maintains a page entitled Tutorials, blog posts and example sites. They don't always list the backends used so you may have to browse all the links to see if you find anything.

DocumentCloud(Backbone.js 出现的项目)维护着一个名为Tutorials, blog posts and example sites 的页面。他们并不总是列出使用的后端,因此您可能需要浏览所有链接以查看是否找到任何内容。

This is quick little tutorialfrom real-world experience, basically wiring a backbone application to some ASPMVC endpoints.

这是来自真实世界经验的快速小教程,基本上是将主干应用程序连接到一些 ASPMVC 端点。

Finally, here is a recent poston Microsoft's own ASP.NET Weblogs called "Integrating Backbone.js with ASP.NET Web API".

最后,这里是Microsoft 自己的 ASP.NET 网络日志上最近的一篇文章,名为“将 Backbone.js 与 ASP.NET Web API 集成”。