javascript - “你接受条款和条件吗?”关于登录表单例份验证 MVC3

标签 javascript jquery asp.net-mvc-3 authentication dialog

我在登录时出现登录对话框时遇到了困难。我需要发生的是,当用户使用内置的 MVC3 身份验证控件登录时,我需要它弹出一个对话框,其中列出一些条款和协议(protocol),并说“如果您点击接受,则表示您同意上述内容”。我目前有这个,但是当我点击取消时,该网站仍然会登录。这是我的代码:

<fieldset>
    <legend>Login</legend>

        <div class="editor-label">
            @Html.LabelFor(model => model.userName)
        </div>
        <div class="focus">
            <div class="editor-field">
                @Html.EditorFor(model => model.userName)
            </div>
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.passWord)
        </div>
        <div class="editor-field">
            @Html.PasswordFor(model => model.passWord)
        </div>

        <p>
            <input type="submit" value="Login" name="btnLogin" id="btnLogin" />
        </p>
        @Html.ValidationSummary(true)


</fieldset>

还有我拥有的 Javascript:

    <script type="text/javascript">
        $(function () {
            $("#btnLogin").click(function () {
                var answer = confirm("Unauthorized access or use of the web content is prohibited.\n" + "By clicking 'OK', you have agreed to the above conditions");
                if (answer) {
                }
                else {
                    $(this).dialog("close");
                }
            });
        });
    </script>

当用户在对话框中点击“取消”时,我如何才能取消登录时的 HttpPost,并在点击“确定”时继续登录?

非常感谢!!

最佳答案

在你的事件处理程序中添加这个

 $("#btnLogin").click(function (event) {
     var answer = confirm("Unauthorized access or use of the web content is prohibited.\n" + "By clicking 'OK', you have agreed to the above conditions");
     if (answer) {

     }
     else{
          $(this).dialog("close");
          event.preventDefault();
     }
 });

添加 event.preventDefault(); 确保防止表单的默认行为

关于javascript - “你接受条款和条件吗?”关于登录表单例份验证 MVC3,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10721727/

相关文章:

javascript - 阻止 url 直接访问 index.php,除非用户单击另一个特定 html 文件(例如 index.html)上的链接

jquery - 单击时更改工具提示文本(切换)

asp.net-mvc-3 - asp.net mvc3 创建一个将始终执行的 Controller 方法

c# - 如何开始编写这个 Orchard 模块

javascript - Twitter Bootstrap Popover 显示后立即隐藏

javascript - 使用ajax时如何查看后端的错误

javascript - jQuery 动态生成范围 slider

asp.net - Html.ActionLink 生成的奇怪链接

javascript - 删除 Internet Explorer 中的滚动条

javascript - 如何将jQuery添加的元素设置到其他元素的后面