2

I've been using ASP.Net MVC for a while now and I've been thinking that this:

<% foreach(ItemRow in Items) { %> <div><%=ItemRow.Description%></div> <% } %>

Reminds me a little too much of ASP Classic and PHP. Yeah there are definite improvements but it still makes me cringe a little.

I've been thinking instead of writing nothing but static html and strictly using jQuery to gather JSON results from webservices and populate the page appropriately. Has anyone tried this approach? What was your experience?

Spencer Ruport
  • 34,865
  • 12
  • 85
  • 147
  • Have you looked at the Razor views, those don't use the "bee stings" <% %> rather a cleaner syntax with @ ?http://weblogs.asp.net/scottgu/archive/2010/07/02/introducing-razor.aspx – Hector Correa Jan 28 '11 at 20:08
  • You do realize that you'll have something like `{{jqueryVar}}` in your javascript template right? Isn't that what you're trying to avoid? It think any text based templating will always resolve around code blocks inside of xml. – John Farrell Jan 31 '11 at 14:08
  • @jfar - Actually my plan is to give html elements classes and ids that jquery can then select and populate with data. It's not so much that I dislike templating I just 1) want the templates to be cached and 2) want the client to handle the population of the data. – Spencer Ruport Feb 07 '11 at 22:37

2 Answers2

3

I have been finding myself doing this more and more. I find it quicker to do simple customer-centric apps. The only "issues" are security and session state management. But it is not a deal killer.

Depends on your view, but one of the positives we have found is that we can build the business and data layers, allow our front end developers to build their interface vision without many restrictions, and finally we can allow a less experienced developer do a lot more of wiring the jquery stuff. Which from a business perspective has a higher ROI as i can dedicate the higher end engineers and developers to do better use of their time.

Victor
  • 4,721
  • 1
  • 26
  • 31
  • I really like your point about how you can sick a less experienced developer on the jquery stuff and how it make it easier on the front end developers. – Spencer Ruport Feb 07 '11 at 22:39
  • How have you approached authentication, authorization and sessions? – Kynth Feb 21 '11 at 12:07
  • 1
    @Kynth Well Sessions are not an issue. We dont use it a lot, but you can still use it via the handler. The hanlder code can check for sessions, validity, etc. Authentication and authorization can be done similarly with a single postback on login and then maintain that server side for example. – Victor Feb 21 '11 at 14:39
  • I haven't completely given up bee stings but I have begun using this approach more on pieces of web applications that I feel will benefit the most from the advantages it offers. – Spencer Ruport Feb 26 '11 at 18:25
1

I agree that having the following:

<% foreach(ItemRow in Items) { %> <div><%=ItemRow.Description%></div> <% } %>

in your view might be ugly. That's why I editor/display templates. So the code looks like this:

<%= Html.DisplayFor(x => x.Items) %>

and in the corresponding display template:

<div><%: Model.Description %></div>

As far as your second question is concerned about using jQuery to gather JSON data from various webservices and build the UI, it is an approach that might work for simpler scenarios but IMHO for complex business applications you might want to consider ASP.NET MVC or even Silverlight.

Darin Dimitrov
  • 1,023,142
  • 271
  • 3,287
  • 2,928
  • I actually am using asp.net mvc right now and I feel like the view code and view html mixed in together gets really icky really fast. My idea was to create "dumb" controllers for the template views and have a set of data oriented controllers that only return JSON. – Spencer Ruport Feb 07 '11 at 22:40