Click here to Skip to main content
15,868,306 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
Updated 15-Dec-19 20:38pm

JavaScript
 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());
        }
    });
}
 
Share this answer
 
v2
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"}))
{




}

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.
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900