Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# MVC3
how to show success message with ajax and jquery after submission of form in mvc3..
I am new in MVC3 and i never used ajax before so can any one tel me solution or example which i can refer...
Posted 21-Oct-11 2:00am
vishal_h1.7K
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

 function FUNCTIONNAME() {
    $.ajax({
        type: "POST",
        url: "YOUR METHOD NAME WHICH IS CALLED",
        data: "{PARAMETER VALUES TO BE PASSED}",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        complete: function () {
        },
        success: function (msg) {                    
           alert("YOUR SUCCESS MESSAGE HERE");
        },
        error: function (msg) {
            alert("Error " + msg.d.toString());
        }
    });
}
  Permalink  
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Hello Vishal,
 
you should be use Ajax Literary as MVC3 having new feature,you can submit your form by using Ajax.Beginform.
 
write following stuff in your view

<script src="@Url.Content("~/Scripts/jquery.unobtrusive-ajax.min.js")" type="text/javascript"></script>
 

br mode="hold" />
@using (Ajax.BeginForm("Sample", new AjaxOptions { UpdateTargetId = "targetId", HttpMethod = "Post"}))
{

<input type="submit" value="Add Unit" />
}
 
it will "Sample" action in controller and append your result in "targetId" div
UpdateTargetId attribute specified where you want to display or update your result on page.
 
\\controller stuff
[httpPost]
public string Sample()
{
return "Action Called by AjaxBeginForm";
}
 
In this way you can submit you page by using Ajax.BeginForm method without refreshing your whole page.
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 304
1 Sergey Alexandrovich Kryukov 255
2 Maciej Los 250
3 Shweta N Mishra 216
4 PIEBALDconsult 174
0 OriginalGriff 7,660
1 Sergey Alexandrovich Kryukov 7,072
2 DamithSL 5,586
3 Manas Bhardwaj 4,946
4 Maciej Los 4,665


Advertise | Privacy | Mobile
Web04 | 2.8.1411023.1 | Last Updated 12 Sep 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100