Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 280
James Avatar asked Dec 09 '22 16:12

James


1 Answers

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.

like image 56
Evan Larsen Avatar answered Jan 06 '23 20:01

Evan Larsen