获取对提交Ajax.BeginForm的表单的引用?

时间:2012-11-15 22:00:52

标签: c# ajax asp.net-mvc

我正在使用Ajax.BeginForm:

@using (Ajax.BeginForm("PostAction", null, new AjaxOptions { HttpMethod = "post", UpdateTargetId = "TargetID", OnComplete = "OnComplete" }, new { @class = "" }))

在javascript方法OnComplete中如何找到提交的表单? (甚至是目标ID)

我需要访问表单容器的数据属性。

感谢。

1 个答案:

答案 0 :(得分:0)

您可以使用类似的内容向您的javascript发送表单的ID或名称

@using (Ajax.BeginForm("PostAction", null, new AjaxOptions { HttpMethod = "post", UpdateTargetId = "TargetID", OnComplete = "OnComplete(xhr, status, 'form1')" }, new { @class = "" }))

的javascript

function OnComplete(xhr, status, formName) {


    alert('Submited Form is  ' + formName);
}