views:

449

answers:

3

I have found jQuery to be a great tool to simplify my MVC Views.

For example, instead of including complicated logic to add alternating styles to my tables I just do this...

$(document).ready(function() {
   $("table.details tr:odd").addClass("detailsAlternatingRow");
   $("table.details tr:even").addClass("detailsRow");                          
});

Do you know of any other good uses of jQuery to slim down the logic in my MVC View?

+2  A: 

Implementing an observer http://google-ajax-examples.googlecode.com/svn/trunk/customevents/jquery.html proved a really good practise. Really nice for code maintenance.

Miau
A: 

Note if you use PHP on the server you can use phpQuery (and I'm sure there are similar server-side jQuery ports for other languages) to do stuff like that without expecting the user to have Javascript enabled.

eyelidlessness
Thanks for that link. Doesn't answer the question, but interesting nonetheless
MDCore
+3  A: 

MVC Framework has a JsonResult that can be very nice to eliminate server round trips and might be able to get rid of some of the logic in your view page. I wrote a tutorial on this available at :

http://www.dev102.com/2008/08/19/jquery-and-the-aspnet-mvc-framework/

Ryan Lanciaux