在_Layout.cshtml中为大型Angular应用程序使用jQuery是否安全?

时间:2015-05-09 07:10:16

标签: jquery asp.net-mvc angularjs

我意识到这个问题有点宽泛,但我希望我能够提供足够的上下文细节来缩小范围。在我很新的项目中,我的任务之一是在用户点击注销链接时添加确认对话框。我在_Layout.cshtml

中更改了如下链接
<div class="row inner">
    @if (Request.IsAuthenticated)
    {
        using (Html.BeginForm("LogOff", "Account", FormMethod.Post, new { @id = "logoutForm", @class = "col-md-8 col-md-offset-2 rightText" }))
        {
            @Html.AntiForgeryToken()
            <a href="@Url.Action("CreateNewMlamApplication", "MlamApplication")"><img src="/img/icons/plusIcon.png" class="icon" /></a>
            <a href="@Url.Action("Index", "Home")"><img src="/img/icons/documentIcon.png" class="icon" /></a>
            @* BKMOD <a href="javascript:document.getElementById('logoutForm').submit()"><img src="/img/icons/gearIcon.png" class="icon" /></a>*@
            <a class="logout-link-confirm" href="#" ><img src="/img/icons/gearIcon.png" class="icon" /></a>
        }
    }
</div>

然后,我将处理程序挂钩到布局底部的logout-link-confirm

    <script>
        $(function() {
            $(".logout-link-confirm").click(function() {
                $('#modalLogoutConfirmation').modal('show');
            });
            $(".logout-link-final").click(function () {
                $('#logoutForm').submit()
            });
        });
    </script>
    @RenderSection("scripts", required: false)
</body>

modalLogoutConfirmation弹出窗口中,当用户确认他们的选择时,我会执行实际注销:$('#logoutForm').submit()

这与angular没有任何关系,因为角度只会在这个布局中的某些正文视图中出现,但是它被加载了,我有点担心我的jQuery可能引入的任何副作用。

1 个答案:

答案 0 :(得分:0)

,这是安全的。我假设模态本身没有任何角度逻辑。即使有,你也必须故意试图干扰Angular,以便发生任何副作用。