Geeks With Blogs
Ed Draper Software Architect

After deciding I wanted to dive full-on into the world of ASP.NET MVC 2, I  began doing some research into what would be the best way to support some of my required AJAX functionality on this platform.  The result of these efforts was a barrage of options – many of which required completely different JScript infrastructure than what I planned to go forward with.  As I’ve been delighted with jQuery so far, I began tossing out all approaches that didn’t natively leverage it… Thus, I planned to resist the temptation to take anymore <script> dependencies whatsoever, unless I thoroughly proved that jQuery could NOT do what I planned to do.

 

Here’s some code I wish I would’ve found early in my research.  This would’ve saved me quite a bit of time and search engine bandwidth. ;-)

 

<script type="text/javascript">
    $(document).ready(function () {


        $('#div_name_here').load('<%=Url.Action("ACTION_NAME_HERE","CONTROLLER_NAME_HERE")%>');

        $('#id_of_link_I_want_trigger_the_ajax_call')
      .bind('click', function (event) {
          $('#div_name_where_I_want_to_have_the_ajax_response_loaded_here').load('<%=Url.Action("ACTION_HERE","CONTROLLER_HERE", )%>');
      })
    })

</script>

Posted on Monday, March 29, 2010 3:33 PM | Back to top


Comments on this post: Ridiculously easy AJAX with ASP.NET MVC and jQuery

# re: Ridiculously easy AJAX with ASP.NET MVC and jQuery
Requesting Gravatar...
Be nice to know what it does...: -)
Left by celia on Apr 05, 2010 4:49 AM

Your comment:
 (will show your gravatar)


Copyright © eddraper | Powered by: GeeksWithBlogs.net