ASP.NET Ajax.BeginForm with angularjs handlers
我有一个剃刀局部视图,它使用Ajax.BeginForm。 问题是我想通过附加到此视图的角度控制器来处理ajax响应。 虽然我可以使用htmlattributes将自定义属性附加到输入,但除了AjaxOptions之外,我找不到任何与Ajax.BeginForm助手类似的东西。 但是如何在其中定义角度控制器方法呢?
upd:我知道OnSuccess等ajax事件可以通过常规的javascript来处理,如下所示:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | @*@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 } Я не зареестрований <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?"); } |
问题是,我可以通过Angular方法处理这些事件吗?
试试这个,
JS:
1 2 3 4 5 6 7 8 | var _myCtrlscope; var app = angular.module("myApp", []); app.controller("myCtrl", function ($scope) { _myCtrlscope = $scope; $scope.foofunction = function (data) { // do your stuff with data here. } }); |
剃刀:
1 2 | Ajax.BeginForm("controllerName","actionName", new AjaxOptions {OnSuccess ="_myCtrlscope.foofunction"} |
让我知道它是否有效,谢谢!