Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How Do You Use jQuery to Simplify Your MVC Views?

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?

like image 325
Elijah Manor Avatar asked Oct 13 '08 16:10

Elijah Manor


2 Answers

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/

like image 178
Ryan Lanciaux Avatar answered Oct 05 '22 23:10

Ryan Lanciaux


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

like image 28
roundcrisis Avatar answered Oct 06 '22 00:10

roundcrisis