jQuery ASP.NET MVC 模态对话框/弹出窗口最佳实践
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/861235/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
ASP.NET MVC modal dialog/popup best practice
提问by Brian David Berman
I am looking for the most standard way to achieve modal dialogs in ASP.NET MVC.
我正在寻找在 ASP.NET MVC 中实现模态对话框的最标准方法。
An example of what I am trying to do is when I select an item from my "list" page, I want the "details" page to be a popup over the list and NOT a new page. I'm not looking for a hack. I want it to be a solution that follows the ASP.NET MVC pattern. I would also prefer not stepping outside jQuery and ASP.NET Ajax (no plugins UNLESS it is emerging as a best practice).
我想要做的一个例子是当我从我的“列表”页面中选择一个项目时,我希望“详细信息”页面是列表上的一个弹出窗口,而不是一个新页面。我不是在寻找黑客。我希望它是一个遵循 ASP.NET MVC 模式的解决方案。我也不想跨出 jQuery 和 ASP.NET Ajax(没有插件,除非它作为最佳实践出现)。
采纳答案by scottm
Lunchy's dialog suggestion is nice. Just make an ajax request to your controller action and have the action return what you want to display, like a partial view with some formatting html. Then, put that html into your dialog, or whatever you plan to display, and show it.
Lunchy 的对话建议很好。只需向您的控制器操作发出 ajax 请求,并让操作返回您想要显示的内容,例如带有某些格式的 html 的部分视图。然后,将该 html 放入您的对话框或您计划显示的任何内容中,并显示它。
回答by Casey Williams
The jQuery UI library has a dialog widget that I use for things like this. While it's a plugin, IMO, the best practice is simply not rolling your own dialog widget.
jQuery UI 库有一个对话框小部件,我用它来做这样的事情。虽然它是一个插件,IMO,但最佳做法是不滚动您自己的对话框小部件。
回答by tvanfosson
One of the things that goes hand in hand with MVC is RESTful urls. That being the case the "standard" way of handling this would be to have the details pull up a new page with it's own, RESTful (and bookmarkable) URL instead of flying a dialog over the page. You could certainly do a "details preview" dialog within the context of the list, but if you're going to interact with the details, I'd consider doing a full request and get the details on it's own page.
与 MVC 密切相关的一件事是 RESTful url。在这种情况下,处理此问题的“标准”方法是让详细信息使用它自己的 RESTful(和书签)URL 拉出一个新页面,而不是在页面上弹出对话框。您当然可以在列表的上下文中进行“详细信息预览”对话框,但是如果您要与详细信息进行交互,我会考虑执行完整请求并在其自己的页面上获取详细信息。