multiple ajax request to action in asp.net mvc

Posted by persian Dev on Stack Overflow See other posts from Stack Overflow or by persian Dev
Published on 2012-03-30T16:31:08Z Indexed on 2012/03/30 17:28 UTC
Read the original article Hit count: 156

I am developing an asp.net mvc application and have ajax calls on my page. Here is a form which I load by ajax call to page :

The form is located in a partial view

<div id="CreateCultureArea">
 <% 
        using (Ajax.BeginForm("CreateCulture", "Admin", new AjaxOptions() { OnSuccess = "handleCreateCulture" }))
        { %>
.....

<% } %>
</div>

The following script is located in a view

    $('.CreateCulture').live('click', function (e) {
        e.preventDefault();
        var idval = this.id;
        $.ajax({
            url: "/Admin/CreateCulture",
            dataType: 'html',
            data: { id: idval },
            success: function (mydata) {

                $("#CultureContentArea").empty();
                $("#CultureContentArea").empty().hide().append(mydata).fadeIn(2000);

                $("form").removeData("validator");
                $("form").removeData("unobtrusiveValidation");
                $.validator.unobtrusive.parse("form");

            },
            type: "GET"
        });
        return false;
    })
</script>

When users click on a link with CreateCulture class, the form is loaded to page. But as I saw the requests in firebug, it calls the action multiple times. I read similar posts like mine on stackoverflow.com and most of them suggested removing repetitive "jquery.unobtrusive-ajax.min.js" calss in page, but as I saw the output page I only see on link to the "jquery.unobtrusive-ajax.min.js" script.

© Stack Overflow or respective owner

Related posts about asp.net-mvc

Related posts about unobtrusive-javascript