Layout = null;
}
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>Index</title>
<script src="~/Scripts/jquery-1.7.1.min.js"></script>//只能用此版本
<script src="~/Scripts/jquery.unobtrusive-ajax.min.js"></script>
<script>
//第一种方式:调用jquery的异步方法
$(function() {$('#btnAdd').click(function() {
$.post(
'@Url.Action("CalcAdd","Home")',
$('#form1').serialize(),
function(msg) {
$('#sum').val(msg);
}
);
});
});
function Success(obj) {
$('#result').val(obj.Sum);
}
</script>
</head>
<body>
<div>
<form id="form1">
<input type="text" name="calc1" />+
<input type="text" name="calc2" />
<input type="button" id="btnAdd" value="加" />
<input type="text" name="sum" id="sum" />
</form>
<hr />
//第二种方法:使用AjaxHelper
@using(Ajax.BeginForm("CalcAdd2", "home", new AjaxOptions(){
OnSuccess = "Success"
}))
{
<input type="text" name="a" />
<span>+</span>
<input type="text" name="b" />
<input type="submit" value="=" />
<input type="text" id="result" />
}
</div>
</body>
</html>