ANDyW
ANDyW

Reputation: 93

ASP.NET MVC 2 Post AJAX from from JavaScript

I got control with strongly typed View, with Ajax.BeginForm(). Now I would like to change submit method from

<input type="submit" id="testClick" value="Submit" />

To some javascript method DoSubmit(). What I tried is :

All those method created normal request (not AJAX), or they didn't work. So anyone know how I can do AJAX submit "Form", from JavaScript and strongly typed mechanism (public AcrionResult MyFormAction(FormModel model); ) will work?

Upvotes: 1

Views: 584

Answers (1)

lomaxx
lomaxx

Reputation: 115863

I've had this work fine for me using the forms plugin for jquery. What I found tho, was that I had to handle the click event, do the ajax submit and then return false to ensure that the normal post didn't occur.

<script type="text/javascript">
    $('#testClick').click(function(){
        $('#form1').ajaxSubmit();
        return false;
    });
</script>

Upvotes: 1

Related Questions