查看:後數據重定向到另一個動作
<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來發表您的形式,任何理由? – 2010-06-29 12:07:35
看看[這個問題](http://stackoverflow.com/questions/2903685/jquery-preventing-redirecttoaction-from-working)。 – silent 2010-06-29 12:00:44