简体   繁体   English

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

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

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? 结合这两个部分时我应该遵循什么策略?

To be fair, Backbone.js (client application) and MVC (server application) should have nothing in common. 公平地说,Backbone.js(客户端应用程序)和MVC(服务器应用程序)应该没有任何共同之处。 The only thing Backbone.js requires is a Restful Api. Backbone.js唯一需要的是Restful Api。 So what I would do is take a look at MVC 4's Web Api ( Example ). 所以我要做的就是看一下MVC 4的Web Api( 例子 )。 There are quite a few tutorials on the subject, but the one I listed gives quite a good overview. 关于这个主题有很多教程,但我列出的那个教程给出了很好的概述。

Once you understand how to implement a Restful API, look at any tutorial on backbone.js that integrates with a server application. 一旦了解了如何实现Restful API,请查看与服务器应用程序集成的backbone.js上的任何教程。 Just substitute your api with the tutorial's api and you should be in business. 只需用教程的api替换你的api就可以了。 Read this book , it is priceless and contains brilliant examples on how to implement a backbone.js application locally and with a server. 阅读本书 ,它是无价的,并包含有关如何在本地和服务器上实现backbone.js应用程序的精彩示例。

On a side note, MVC 4's Web API integrates perfectly with backbone. 另外,MVC 4的Web API与骨干网完美集成。 Have a look at a plugin developed by Addy Osmani, Backbone.Paginator . 看看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和odata过滤器轻松实现过滤,分页,跳过,排序等。

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. 在学习了Backbone.js并在一些项目中使用它之后,我发现我的大部分时间都花在了解如何使用它上,而不是我的后端正在做什么。 In terms of ASPMVC, you setup a few controller actions that return JSON. 就ASPMVC而言,您设置了一些返回JSON的控制器操作。

Rob Connery uses Backbone.js with MVC3 in his series Real-World ASP.NET MVC3 on 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. 第6集 - BackboneJS - 用于完全向您介绍骨干和ASPMVC3集成。 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. 不幸的是,你必须以32美元的价格购买整个系列,并且有助于观察整个系列以了解最新的产品。 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. 此外,我不同意他接近视频中所有内容的方式,但如果你是新手,他对Backbone.js的使用和描述会非常有用。

DocumentCloud (the project from which Backbone.js emerged) maintains a page entitled Tutorials, blog posts and example sites . DocumentCloud(Backbone.js出现的项目)维护着一个名为Tutorials,博客文章和示例站点的页面 They don't always list the backends used so you may have to browse all the links to see if you find anything. 它们并不总是列出使用的后端,因此您可能必须浏览所有链接以查看是否找到任何内容。

This is quick little tutorial from real-world experience, basically wiring a backbone application to some ASPMVC endpoints. 这是来自实际经验的快速小教程 ,基本上将骨干应用程序连接到一些ASPMVC端点。

Finally, here is a recent post on Microsoft's own ASP.NET Weblogs called "Integrating Backbone.js with ASP.NET Web API". 最后, 这是一篇关于微软自己的ASP.NET Weblog的帖子 ,名为“将Backbone.js与ASP.NET Web API集成”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM