【发布时间】:2010-06-29 11:56:54
【问题描述】:
查看:
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<h2>Index</h2>
<script type="text/javascript">
$(document).ready(function() {
$(document).ready(function() {
$("#example").submit(function() {
var id = $("#id").val();
var prezime = $("#prezime").val();
$.post("/jQueryPost/PostingData", { id: id, prezime: prezime }, function(res) {
if (res.redirect) {
window.location.href = res.redirect;
return;
}
}, "json");
return false;
});
});
</script>
<form id="example" method = "post">
Id:<input id="id" type="text" />
Prezime:<input id="prezime" type="text" />
<p>
<input type="submit" value="Post Data" />
</p>
</form>
</asp:Content>
控制器动作:
[HttpPost]
public ActionResult PostingData(int id, string prezime)
{
//some code
return Json(new { redirect = Url.Action("Create") });
}
Tnx,这段代码解决了我的问题
【问题讨论】:
-
有什么理由需要使用 javascript 来发布表单?
标签: asp.net-mvc