我开始学习ASP.Net MVC(发布候选版),但遇到了一些问题。也许我只是过于挑剔,但我想问问。
我想使用内置(扩展)的ASP.Net Ajax方法来调用我的控制器,名为“GetNames”,它返回一个JsonResult对象。我看到了使用$.getJSON() jQuery方法的示例,但我更喜欢像这样做:
<%using ( Ajax.BeginForm("GetNames", new AjaxOptions() { OnSuccess = "GetNamesSuccess", OnBegin = "GetNamesBegin", OnComplete = "GetNamesComplte", OnFailure = "GetNamesFailure" } ) ) { %>
<%=Html.TextBox("DummyData") %>
<input type=submit />
<% } %>
<script type="text/javascript">
function GetNamesSuccess()
{
alert("Success");
}
function GetNamesBegin()
{
alert("Begin");
}
function GetNamesComplete()
{
alert("Complete");
}
function GetNamesFailure()
{
alert("Failure");
}
</script>
当我点击提交按钮时,我没有收到任何警报,并且会提示我下载一个包含Json对象文本的文件,这表明至少控制器方法运行正常。但这不是我想要的行为...理想情况下,Ajax.BeginForm应该设置好,使得Json对象可以传递给OnSuccess或OnComplete方法。
有办法实现这个吗?