如何从 MVC 控制器显示消息框

发布于 2024-08-20 07:23:21 字数 120 浏览 3 评论 0 原文

谁能告诉我如何从 MVC 控制器显示消息框吗? 场景是—— 我想显示一个带有是/否按钮的消息框。单击“是”后,我想显示一个确认消息框。 我想使用 MVC 控制器来做到这一点? 我该怎么做?

提前致谢, 卡普斯

can anyone please tell about showing message box from MVC controller?
The scenario is -
I want to show a message box with Yes/No buttons. On clicking Yes i want to show a confirmation message box.
I want to do this using MVC controller?
How can I do this?

Thanks in advance,
Kaps

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

水水月牙 2024-08-27 07:23:21
if (confirm('Are you sure?'))
{
$.post("Confirmation", {myresponse: 'yes'}, function(data)
{
$.("#mymodal").html(data);
}
}

这样它就会命中 actionmethod,并让它知道已做出“是”确认,并且 actionmethod 可以发回 html 标记。

if (confirm('Are you sure?'))
{
$.post("Confirmation", {myresponse: 'yes'}, function(data)
{
$.("#mymodal").html(data);
}
}

That way it hits the actionmethod and lets it know that a yes confirmation was made and the actionmethod can send back the html markup.

回梦 2024-08-27 07:23:21

你说的是客户端消息框吗?如果是这样,请尝试使用 JavaScript 的确认对话框。

if (confirm('你确定吗?')){}

Are you talking about the client message box? If so, try to use JavaScript's confirm dialog.

if (confirm('Are you sure?')){}
歌枕肩 2024-08-27 07:23:21

控制器的操作方法通常不控制视图渲染的内容,而是简单地声明要显示的视图(即返回 this.View("MyView"))以及视图应用于渲染的数据如果需要的话,它本身。

您可以使用 JavaScriptResult,但是您在某种程度上破坏了关注点分离,控制器应该指示要渲染哪个视图,而不是视图包含的内容。

这是关于 JavaScriptResult 的一篇很好的文章,以及为什么这是一个坏主意: http://devlicio.us/blogs/billy_mccafferty/archive/2009/02/07/beware-of-asp-net-mvc-javascriptresult.aspx

The Controller's action method generally does not control what the View renders, rather it simply states which view to display (ie. return this.View("MyView")) and the data the view should use to rendering itself if necessary.

You can use JavaScriptResult however you are breaking separation of concerns somewhat, the Controller should dictate which view to render, not what the view contains.

Here's a good write up on JavaScriptResult and why it's a bad idea: http://devlicio.us/blogs/billy_mccafferty/archive/2009/02/07/beware-of-asp-net-mvc-javascriptresult.aspx

戏剧牡丹亭 2024-08-27 07:23:21

我想你想做这样的事情:

http://net.tutsplus.com/tutorials/javascript-ajax/5-ways-to-make-ajax-calls-with-jquery/

在控制器端,您希望该方法返回 json.

I think you want to do something like this:

http://net.tutsplus.com/tutorials/javascript-ajax/5-ways-to-make-ajax-calls-with-jquery/

On the controller side you want the method to return json.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文