[英]ASP.NET Ajax.BeginForm with angularjs handlers
I have a razor partial view which makes use of Ajax.BeginForm. 我有一个使用Ajax.BeginForm的局部视图。 Problem is that I want to handle ajax response via angular controller which is attached to this view.
问题是我想通过附加到此视图的角度控制器处理ajax响应。 While I can attach custom attributes to inputs using htmlattributes, I couldn't find anything similar for Ajax.BeginForm helper aside from AjaxOptions.
尽管我可以使用htmlattributes将自定义属性附加到输入,但是除了AjaxOptions之外,我找不到与Ajax.BeginForm帮助器类似的东西。 But how can I define angular controller method inside it?
但是,如何在其中定义角度控制器方法呢?
upd: I know that OnSuccess etc. ajax events can be handled via regular javascript like below: 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>
question is, can I handle this events via Angular methods? 问题是,我可以通过Angular方法处理此事件吗?
try this, JS: 试试这个,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"}
Let me know if it works, thanks! 让我知道它是否有效,谢谢!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.