如何从 MVC 控制器显示消息框
谁能告诉我如何从 MVC 控制器显示消息框吗? 场景是—— 我想显示一个带有是/否按钮的消息框。单击“是”后,我想显示一个确认消息框。 我想使用 MVC 控制器来做到这一点? 我该怎么做?
提前致谢, 卡普斯
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
谁能告诉我如何从 MVC 控制器显示消息框吗? 场景是—— 我想显示一个带有是/否按钮的消息框。单击“是”后,我想显示一个确认消息框。 我想使用 MVC 控制器来做到这一点? 我该怎么做?
提前致谢, 卡普斯
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(4)
这样它就会命中 actionmethod,并让它知道已做出“是”确认,并且 actionmethod 可以发回 html 标记。
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.
你说的是客户端消息框吗?如果是这样,请尝试使用 JavaScript 的确认对话框。
Are you talking about the client message box? If so, try to use JavaScript's confirm dialog.
控制器的操作方法通常不控制视图渲染的内容,而是简单地声明要显示的视图(即返回 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
我想你想做这样的事情:
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.