Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery Templates vs Partial Views in ASP.NET MVC

I'm taking a look at jQuery templates. It looks really interesting - easy syntax, easy to use, very clean.

However, I can't really see why it's better to use jQuery templates instead of simply fetching partial views via AJAX. It simply seems like the partial views would be much easier to maintain and helps to avoid duplication of code.

I want to use jQuery templates. But when would it be better than partial views?

like image 870
Jaco Pretorius Avatar asked Feb 13 '11 07:02

Jaco Pretorius


1 Answers

I agree that these do overlap. There are several different ways to implement the same piece of software, and much of your decision on what to use depends on your personal preference and the context of your software.

Partial view advantages:

  • Type-safe (if using strongly-typed viewmodels)
  • Allows static syntax and type checking.
  • Full code completion / syntax highlighting support in Visual Studio

jQuery Templates advantages:

  • Allows the page to be updated before performing postbacks or without any postbacks to the server side at all. This can be handy when creating heavily ajaxed interfaces, possibly also with html5-driven offline capabilities.
  • You can retrieve data from the server in JSON format and render that to HTML. JSON is much shorter that HTML formatting, so this can make a difference in page loading times for long lists of data entries when using a slow internet connection.

So in essence partial views are the more stable and jquery templates are (for ajax websites) the more performant choice. I therefore use partial views for less frequented web pages which need to be developed quickly and jQuery templates for heavily ajaxed web pages where performance really matters.

like image 50
Adrian Grigore Avatar answered Oct 18 '22 08:10

Adrian Grigore