如何使用Durandal.js,MVC3局部视图 [英] How to use partial views with Durandal.js, mvc3

查看:216
本文介绍了如何使用Durandal.js,MVC3局部视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我注意到所有的在App / views文件夹的视图类型的HTML,而不是CSHTML。我如何使用,我习惯了如剃刀PartialViews和MVC3的东西呢?

I noticed all of the views in the App/views folder are of type html, not cshtml. How do I use PartialViews and mvc3 things that I am accustomed to such as razor?

推荐答案

迪朗达尔是专为创建完全生活在一个页面内的应用程序。这样做的典型应用该类超支是用户的经验是,像桌面应用程序中。此外,这使应用程序可以方便地移植到 PhoneGap的它可以活作为原生移动应用程序,甚至移植到使用桌面应用程序<一HREF =htt​​p://appjs.org/> appjs 。

Durandal is designed for creating an application that lives entirely inside of one page. The benifits of this is the user experience is that like of a desktop application. Also, this allows the application to easily be ported to phonegap where it can live as a native mobile application or even ported to a desktop application using appjs.

通过让您的整个应用程序如HTML,JS和CSS文件,您可以 COM preSS /缩小/丑化整个应用程序到一个文件中有一台服务器为您服务整个应用程序。然后应用程序只是调用Web服务来获取其数据。这可能是一个MVC控制器,Web API或一些web服务返回回数据。您可以使用此数据绑定到浏览器的模板,并产生要显示的视图。

By having your entire application as html, js, and css files you can compress/minify/uglify your entire application into one file and have a server serve you entire application. Then the application just calls web services to get its data. Which could be a mvc controller, a web api, or some webservice that returns back data. You use this data to bind to an browser template and generate a view to be displayed.

您也可以有一个混合应用程序在您的服务器可以服务多个迪朗达尔水疗中心,您将不得不应用程序的集合由一个单一的网站提供服务了。

You can also have a hybrid application where your server can serve multiple durandal SPAs, which you would then have a collection of applications being served by a single site.

我看到很多人从MVC背景的要求以及我为什么不能用CSHTML文件我的HTML。简短的回答是可以,但你这样做失去了很多benifit的。当您在服务器渲染你的HTML文件,那么你再也不能融为一体preSS /缩小/丑化整个应用程序,因为你是依靠在服务器上为您生成的HTML。

I see many people coming from the MVC background asking well why can't I use CSHTML files for my HTML. The short answer is you can but you lose a lot of benifit from doing this. When you have the server render your html files then you no longer can compress/minify/uglify your entire application because you are relying on the server to generate the html for you.

如果您preFER CSHTML那么传统上这是一个丰富的AJAX应用程序在您的用户打电话到一些URI和服务器将生成基于关闭的一些数据的HTML,将呈现的HTML返回给用户在那里在屏幕的某个地方贴上。有了这个过程中,你有什么是AJAX丰富的网站,但不是一个SPA。你失去了,使这个应用程序的本地移动应用程序,甚至是桌面应用程序的能力。

If you prefer cshtml then traditionally this is for an AJAX-rich application where your user makes a call to some uri and the server generates the HTML based off some data, sends that rendered html back to the user where it is pasted somewhere in the screen. With this process what you have is an AJAX rich site but not a SPA. You lose the ability to make this application a native mobile application or even a desktop application.

这篇关于如何使用Durandal.js,MVC3局部视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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