如果用户未登录,则触发jQuery UI对话框。 [英] trigger an jQuery UI Dialog if user not logged in.
问题描述
您好。
在我的网站上我有两个登录操作,第一个用于用户正在按一个按钮登录,这会触发一个jQuery UI对话框。第二个是普通视图,如果用户未获得授权,我会使用该视图。但我喜欢做的是,用户不是授权,它打开Login jquery ui对话框而不是重定向到另一个视图。
这就是我目前打开对话框的方式,
Hello.
On my website I have two login action, the first is used then an user is pushing an button to login, which trigger an jQuery UI Dialog. The second is an normal view, which i use if an user isn''t Authorized. But what i liked to do instead, is an user is not Authorized, it opens the Login jquery ui dialog instead of redirection to another view.
This is how i currently are opening the dialog,
$(".openLoginDialog").on("click", function (e) {
e.preventDefault();
$("<div></div>")
.addClass("dialog")
.attr("id", $(this).attr("data-dialog-id"))
.appendTo("body")
.dialog({
title: $(this).attr("data-dialog-title"),
create: function (event, ui) {},
close: function () { $(this).remove() },
open: function (event, ui) {},
modal: true,
position: ['center', 130],
minWidth: 510,
resizable: true,
zIndex: 20000
})
.load(this.href);
});
因为对话框中的内容是partialView,所以它的调用方式如下:
Because the content in the dialog is an partialView it''s called like this:
<div class="items iconlogin highligth-br"><a class="openLoginDialog" data-dialog-id="LoginDialog" data-dialog-title="Login" href="@Url.Action("LogOn", "Authentication", new { returnUrl = Request.Url.ToString() })">Login</a></div>
另外为了帮助我控制非授权,我已经覆盖了这个电话。
Also to help me controlling the not Authorized, i have overriden this calls.
public override void OnAuthorization(AuthorizationContext filterContext)
{
filterContext.Result = new RedirectToRouteResult(new
RouteValueDictionary(new { controller = "Authentication", action = "AccessDenied" }));
}
我找不到任何人这样做过。请帮助。
最好的关注Morten Starck
I have not been able to find anybody who has done that. Please help.
Best regard Morten Starck
推荐答案
( .openLoginDialog)。on( click , function (e){
e.preventDefault();
(".openLoginDialog").on("click", function (e) { e.preventDefault();
( < div>< / div>)
.addClass( 对话框)
.attr( id,
( this )。attr( data-dialog-id))
.appendTo( body)
.dialog({
title:
(this).attr("data-dialog-id")) .appendTo("body") .dialog({ title:
这篇关于如果用户未登录,则触发jQuery UI对话框。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!