Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

possible for asp.net mvc 2 to render views as jquery-tmpl templates?

I like the idea of the new MS-developed jQuery plugins, Templates and DataLinking, and actually have a need in my day job where they could possibly prove valuable. Thing is, the html I would need to template is non-trivial html that takes advantage of both built-in and custom Html helper methods via the MVC 2 framework. Additionally, there is conditional rendering based on values of the bound ViewModel.

I could go about faithfully reproducing the rendering logic from MVC view syntax to jquery-tmpl syntax, which would include figuring out all generated HTML from the MVC helper functions used. However, this is both tedious and time-consuming. Not to mention other concerns such as server-side & client-side validation and other HTML helper functions such as AntiForgeryToken(), though such concerns could probably be side-stepped by being smart with confining jquery-tmpl use.

I wonder, can we take advantage of the logic and structure already defined by the MVC partial view and have it render a jquery-tmpl template instead of straight HTML? At first glance, it would appear to be a matter of translating MVC view syntax to jQuery-tmpl syntax, preserving all loops, conditions, etc.

Is this even possible? I don't know the MVC framework through and through, but do know it offers great extensibility. This situation seems like it could be valuable if figured out, yes? Or am I even off-based in thinking that? Any thoughts or suggestions?

like image 897
kdawg Avatar asked Nov 02 '10 17:11

kdawg


1 Answers

Seems like you'd probably want to implement this as a custom ViewEngine. ViewEngines are pluggable in MVC. A JQuery-Tmpl ViewEngine would probably just speak JSON with the server. Blobs of template markup could also be presented to the ViewEngine as the values of child properties in response messages. It would then be the job of the ViewEngine to render the templates and place them into region targets, etc. Sounds eerily familiar.. ;)

like image 144
Joel Avatar answered Nov 14 '22 11:11

Joel