Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can i share templates between my ASP.NET MVC backend and my backbone.js frontend?

I'm buliding an application in ASP.NET MVC and considering backbone.js for the client side interaction etc..

Ideally when the pages are loaded i'd like to have all the existing content pre-rendered on the server side and then any new content rendered by backbone.js on the fly.

Naturally i dont really want to write my templates twice.

I'm considering having most of the application templated using the razor view engine and then using mustache templates for the small areas that need to be shared between server and front end.

My question is, what does the actual technical implementation of this look like?

Can you provide code samples of how you would achieve this?

For example which library would you use to render the template on the server and then would you manually extract the text from the template file and inject it into the javascript?

like image 418
Daniel Upton Avatar asked Nov 17 '11 12:11

Daniel Upton


People also ask

Is Backbone JS frontend or backend?

Backend Synchronization BackboneJS is use with the front-end and back-end systems, allows the synchronization with the backend to provide support to RESTful APIs.

Is backbone a MVC?

Backbone. js is a model view controller (MVC) Web application framework that provides structure to JavaScript-heavy applications. This is done by supplying models with custom events and key-value binding, views using declarative event handling and collections with a rich application programming interface (API).

Which frontend framework is best for ASP NET core?

React. js is very popular and has a lot of community and 3rd party support. Microsoft's answer for SPA apps is Blazor. Blazor is what I would recommend.

What is Backbone js used for?

BackboneJS allows developing of applications and the frontend in a much easier way by using JavaScript functions. BackboneJS provides various building blocks such as models, views, events, routers and collections for assembling the client side web applications.


2 Answers

Not so much a technical as a functional answer see my answer here for a functional flow incorporating server- and clientside rendering (using Mustache)

Accessibility and all these JavaScript frameworks

hth,

like image 103
Geert-Jan Avatar answered Sep 18 '22 20:09

Geert-Jan


I am evaluating Razor Client Templates (GitHub) at the moment. It is in version 0.7.0 and seems a bit brittle currently.

It allows you to reference individual partial razor views as JavaScript templates.

As part of a commercial product we will be taking this further to output Handlebars.js compatible templates from our Razor partials.

like image 44
Andy Hoyle Avatar answered Sep 18 '22 20:09

Andy Hoyle