授权和Jquery对话框问题
对于需要角色的操作,我在 Jquery 对话框中遇到了一个小问题。 在我的示例中,用户可以单击删除按钮,并且必须确认该操作。 在我的控制器中,删除操作需要角色,如果用户处于所需角色,则对象将被删除。
问题:如果出现以下情况如何提醒用户 * 元素被删除(重定向到索引视图) * 出现错误(带有消息的警报) * 他无权删除(通过消息发出警报)
在使用授权过滤器之前,删除操作返回一个 JSON,其中包含一个布尔值(指示是否存在错误)、一个成功时重定向的 URL 以及一条警报消息错误时。
由于我无法从过滤器返回 JSON,因此我使用授权过滤器创建了另一个方法,该方法返回包含确认内容的部分视图。如果用户没有权限,过滤器将返回包含未经授权的异常内容的部分视图。
问题:如何区分返回的是哪个部分视图。当我创建对话框时,我需要知道按钮的功能。
谢谢!
I have a little problem with a Jquery dialog for an action that requires a role.
In my example, the user can click on a delete button and must confirm the action.
In my controller, the Delete action requires a role, if the user is in the required role, the object is deleted.
The problem: How to alert the user if
* the element was deleted (redirect to the Index view)
* there was an error (alert with the message)
* he doesn't have the rights to delete (alert with the message)
Before using the authorize filter, the delete action returned a JSON with a Boolean that indicates if there was an error, an URL to redirect on success and a message to alert on error.
As I can't return a JSON from my filter, I created an other method with the authorize filter that returns a partial view with the confirm content. If the user doesn't have the rights, the filter returns a partial view with an unauthorized exception content.
The problem: How to distinct which partial view was returned. When I create the dialog, I need to know for the buttons function.
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我建议在您的模型中添加一些内容,其中 jquery 对话框的构建类似于 CanDeleteItem 标志。然后使用该信息构建对话,而不是假设他们具有删除权限。显示用户无法使用的按钮是一个坏主意。
对于其他错误情况,假设您使用 jquery.ajax 发布到删除操作,则当控制器抛出异常时,应引发 onerror 事件。
I would suggest adding something to your Model where the jquery dialog is getting built like CanDeleteItem flag. Then build your dialog using that information instead of assuming they have the permissions to delete. Showing a button that the user can't use is a bad idea.
For other error situations, assuming you are using jquery.ajax to post to the delete action, the onerror event should be raised when an exception is thrown from the controller.
通过向 Global.asax 添加代码找到了解决方案:
Found a solution by adding code to the Global.asax: