Click here to Skip to main content
14,485,233 members
Rate this:
Please Sign up or sign in to vote.
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
Rate this:
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"}))
{




}

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.
   
Rate this:
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());
        }
    });
}
   
v2

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




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