ASP.NET MVC登录模态对话框/收藏 [英] ASP.NET MVC Login Modal Dialog/lightbox

查看:815
本文介绍了ASP.NET MVC登录模态对话框/收藏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望创建一个登录灯箱/模态对话框到我的网站,该网站是建立与asp.net mvc的。不过,我能想到的唯一的办法就是链接到受限制的部分时,把逻辑进入的onclick事件为超链接。我想preFER,所以我仍然可以使用Authrisation行为过滤器,当你点击一个链接到一个action方法上需要authrisation其过程使用到实际的链接之前会显示灯箱/模态对话框。这样做的原因是我不想preform不具有到remeber把在用于链接的事件的宋衍涛任务

I was hoping to create a lightbox/modal dialog for login into my website which is built with asp.net mvc. However the only way i can think of is to put logic into the onClick events for the hyperlinks when linking to restricted sections. I would prefer it so I could still use the Authrisation action filter, and when you click on a link to a action method which requires authrisation it would show the lightbox/modal dialog before proceding on to the actual link. The reason for this is i don't want preform the repetive task of having to remeber to put in the events for the links.

只有这样,才能实现这个,我能想到的是,以preform从服务器到客户端AJAX推/彗星显示在authrisation过滤箱,控制器将继续之前。也有不执行阿贾克斯那么多机制的文档推压在asp.net的MVC /彗星。

The only way to implement this which i can think of is to preform a ajax push/comet from server to client to show the box in a authrisation filter before the controller continues on. There is also not that much documention of performing ajax pushes/comet in asp.net mvc.

有没有办法simplier?

Is there a simplier way?

Digg的登录窗口就是一个例子。

The digg login window is a example of this.

推荐答案

使用一个类来装点链接,如果你有一些做的,一些不要求登录的操作,当请求没有被授权。当有人点击需要授权的链接,然后弹出的模态对话框。这个对话框应该张贴与链路的实际URL单击了设置为操作的参数RETURNURL您的登录操作。如果登录失败,重定向到登录视图(追加RETURNURL到后动作的登录表单)。

Use a class to decorate links to actions that require login if you have some that do and some that don't, when the request isn't authorized. When someone clicks a link requiring authorization, then popup your modal dialog. This dialog should post to your login action with the actual url of the link clicked set as the returnUrl parameter for the action. If the login fails, redirect to the login view (appending the returnUrl to the post action for the login form).

请注意:这是假设您正在使用jQuery UI的对话,但不使用对话框的按钮界面。您可能需要在UI类添加到该按钮的自己,以获得正确的造型。如果你不使用jQuery UI然后调整对话框code用对话的工作。

Note: This assumes that you are using the jQuery UI dialog, but doesn't use the dialog's button interface. You may need to add the UI classes to the button's yourself to get the correct styling. If you're not using jQuery UI then adjust the dialog code to work with your dialogs.

<% if (!Request.IsAuthenticated) { %>
$(function() {
    $('#loginDialog').hide().dialog({
         modal: true,
         ...
    });
    $('a.requires-login').click( function() {
         returnUrl = $(this).attr('href');
         $('#loginDialog').find('#returnUrl').val(returnUrl);
         $('#loginDialog').dialog('open');
         return false;
    });
<% } %>

<% if (!Request.IsAuthenticated) { %>
<div id="loginDialog">
    <% using (Html.BeginForm("Login","Account")) { %>
         <%= Html.TextBox( "returnUrl", null, new { style = "display: none;" } ) %>
         ... rest of form ...
    <% } %>
</div>
<% } %>

这篇关于ASP.NET MVC登录模态对话框/收藏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆