//需要引入:
<head>
<script src="~/Scripts/jquery-1.8.2.js"></script>
<script src="~/Scripts/jquery.unobtrusive-ajax.js"></script>
<script type="text/javascript">
function newFunction(data) {
alert(data);
}
</script>
</head>
view页面:
<div>
@using (Ajax.BeginForm("GetDate","MicroAjax",new AjaxOptions(){Confirm =
"您确认要提交吗?",
HttpMethod = "Post",
InsertionMode = InsertionMode.Replace,
UpdateTargetId = "result",
OnSuccess = "newFunction",
LoadingElementId = "loading"
}))
{
<div>
用户名:<input type="text" name="UserName"/><br/>
密码:<input type="text" name="Password"/><br/>
<input type="submit" value="提交"/>
</div>
<div id="result"></div>
<div id="loading" style="display: none;">
<img src="~/Content/ico_loading2.gif" />
</div>
}
</div>