Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
812 views
in Technique[技术] by (71.8m points)

asp.net mvc - How to use partial views with Durandal.js, 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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.

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.

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.

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...