如何从Controller mvc调用Javascript函数或警报 [英] How to call Javascript Function or alert from Controller mvc

查看:55
本文介绍了如何从Controller mvc调用Javascript函数或警报的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何从控制器调用Javascript函数或警报mvc



Script.RegisterClientScriptBlock如何调用我不想返回

i想要说

提醒('数据保存')



并留在同一页

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

推荐答案

1.在MVC中还有其他方法可以做到,而不应该像在ASP.NET中那样。



2.最简单的方法要做(我认为你想要的)就是在你的视图(页面)中使用AJAX调用来控制你的控制器上的保存方法,并成功显示你的警告信息,如下一个例子所示:

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:
@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" />
}


这篇关于如何从Controller mvc调用Javascript函数或警报的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆