Skip to content

Submitting an AJAX Form with ASP.NET MVC + jQuery

I don’t have a lot of time to blog about this, and it is something I wanted to blog about weeks ago, so while I have the links on hand, here are the links I used to move away from ASP.NET MVC’s built in Ajax methods utilising the Microsoft Ajax JavaScript library (you know, your Ajax.BeginForm()) which in my opinion does not offer as much control and fine tuning, and over to the promise land of jQuery AJAX & JSON data structures.

These are the links I learnt from, I used best bits out of them all to come up with something decent to my knowledge: -


I especially found great value in the encosia.com ones.

And now to cut the fat, just a quick sample of how I would go about returning data via Ajax with jQuery (“getexamplemessage” returns a JsonResult from my ASP.NET MVC controller action, all data for sample purposes):

    function getExampleMessage() {
        var ajaxLoadImgId = 'ajaxLoadingGetExampleMessage';
        $("#" + ajaxLoadImgId).html(ajaxLoadImage);
        $('#MessageFormat').hide();
        $("#" + ajaxLoadImgId).show();
        var moduleId = $("input#FromModuleID").attr("value");
        var messageTypeId = $("input#MessageTypeID").attr("value");
        $.ajax({
            type: "GET",
            url: "/configuration/module/getexamplemessage",
            data: {
                moduleId: moduleId,
                messageTypeId: messageTypeId
            },
            dataType: "json",
            success: function(result) {
                $("#" + ajaxLoadImgId).hide();
                // Insert the returned HTML into the
. $('#MessageFormat').text(result.exampleMessage).fadeIn('fast'); //$("textarea#MessageToTranslate").val(result.exampleMessage); }, error: function(req, status, error) { $('#MessageFormat').text('Could not load example translation message, please try reloading the page.'); $("#" + ajaxLoadImgId).hide(); $('#MessageFormat').show(); } }); }
VN:F [1.9.10_1130]
Rating: 3.5/5 (26 votes cast)
VN:F [1.9.10_1130]
Rating: +2 (from 4 votes)
Submitting an AJAX Form with ASP.NET MVC + jQuery, 3.5 out of 5 based on 26 ratings
Bookmark and Share
kick it on DotNetKicks.com
Shout it

NOW, FOR A WORD FROM OUR SPONSORS

2 Trackbacks/Pingbacks

  1. ASP.NET MVC Archived Blog Posts, Page 1 on 28-Jan-09 at 1:10 pm

    [...] to VoteSubmitting an AJAX Form with ASP.NET MVC + jQuery « {Programming … (1/26/2009)Monday, January 26, 2009 from unknownI don’t have a lot of time to blog about this, and it is [...]

  2. DotNetShoutout on 05-Feb-09 at 10:07 am

    Submitting an AJAX Form with ASP.NET MVC + jQuery « {Programming} & Life…

    Thank you for submitting this cool story – Trackback from DotNetShoutout…

    VA:F [1.9.10_1130]
    Rating: 3.1/5 (7 votes cast)
    VA:F [1.9.10_1130]
    Rating: +1 (from 3 votes)

Post a Comment

Your email is never published nor shared. Required fields are marked *
*
*

My name is Graham O'Neale and I'm a software architect from Gold Coast, Australia. I am an overtime thinker, full time coder and awake part time in the real world. I have a keen interest in software development, particularly in the realm of programming (C#, ASP.NET, ASP.NET MVC, LINQ (2 SQL), Entity Framework, Silverlight, Blend, WCF, WPF) and a keen interest in the cutting edge and innovation. I have a new found love for design patterns, ALT.NET practices and well crafted software architecture. The purpose of this blog is to express any thoughts, findings, tips and gripes along my travels in the wonderful world of coding and technology...