Click here to Skip to main content
15,894,630 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
How to call Javascript Function or alert from Controller mvc

Script.RegisterClientScriptBlock how to call i dont want to return
i want to say
alert('data save')

and stay on same page
Posted

1 solution

1.In MVC there are other ways to do it, and not should be done like in ASP.NET.

2.The best and easy way to do (that I supposed that you want) is to use AJAX call from your view (page) to call you "Save" method on your controller and for success to show your alert message, like in the next example:
HEML
@using (Ajax.BeginForm("Save", "YourController",
                new AjaxOptions
                {
                    HttpMethod = "POST",
                    OnSuccess = "alert('Data saved!')"
                }))
{
//your razor code for collecting the user input !
//...
<input type="submit" name="save" value="Save" />
}
 
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