ASP.净Ajax.用angularjs处理程序BeginForm

本文关键字:处理 程序 BeginForm angularjs Ajax ASP | 更新日期: 2023-09-27 18:03:54

我有一个razor局部视图,它使用Ajax.BeginForm。问题是,我想处理ajax响应通过角控制器这是附加到这个视图。虽然我可以使用html属性将自定义属性附加到输入,但我找不到类似的Ajax属性。BeginForm助手除了AjaxOptions。但是我怎么在里面定义角控制器方法呢?

upd:我知道OnSuccess等ajax事件可以通过常规javascript处理,如下所示:

<div class="content">
        @*@using (Ajax.BeginForm("AccountCheckLogin2", "Login", null, new AjaxOptions { OnFailure = "OnFailure", OnSuccess = "OnSuccess", UpdateTargetId = "result" }, new { @name = "form", role = "form" }))*@
        @using (Ajax.BeginForm("AccountCheckLogin2", "Login", new AjaxOptions { OnSuccess = "OnSuccessLogin", OnBegin = "OnBeginLogin", OnComplete = "OnCompleteLogin", OnFailure = "OnFailureLogin" }))
        {
            //inputs here
        }
           <a class="link" href="/Registration/Registration">Я не зареестрований</a>
        </div>
</div>
<script type="text/javascript">       
    function OnSuccessLogin(response) {
        if (response.ResponseCode == "1") {
            window.location = "/";
        }
        else
        {                
            $("#LoginValidationSummary ul").append("<li>"+response.ResponseMessage+"</li>");
        }
    }
    function OnBeginLogin() {
        $("#loginSubmit").prop("disabled", true);
    }
    function OnCompleteLogin() {
        $("#loginSubmit").prop("disabled", false);
    }
    function OnFailure() {
        alert("Whoops! That didn't go so well did it?");
    }
</script>

问题是,我可以通过Angular的方法来处理这些事件吗?

ASP.净Ajax.用angularjs处理程序BeginForm

试试这个,JS:

var _myCtrlscope;
var app = angular.module("myApp", []);
app.controller("myCtrl", function ($scope) {
_myCtrlscope = $scope;           
 $scope.foofunction = function (data) {
            // do your stuff with data here.
        }
    });

剃刀:

Ajax.BeginForm("controllerName", "actionName", 
new AjaxOptions {OnSuccess = "_myCtrlscope.foofunction"}

让我知道它是否有效,谢谢!