後,我有這樣的:
- HTML:表單+ jQuery的
- 控制器
我通過後jQuery的形式,在控制器中,有一個錯誤在我使用的函數中,我將狀態碼設置爲500.我想在$ .post的「.error」中顯示我的視圖的內容。正如你看到的我測試了警報,但我從來沒有看到的視圖的內容
HTML
@using (Html.BeginForm("Save","Customer"))
{
}
var jqxhr = $.post("Customer/Save", function() {
alert("success");
})
.success(function() {})
.error(function (jqXHR, status, error) {
alert(jqXHR);
alert(status),
alert(error);
})
.complete(function() {});
* 控制器*
public ActionResult Save(MyModel model)
{
//Action1 here
//....
if(Actiion1 failed)
{
Response.StatusCode = 500
return PartialView("Error");
}
return View("MyView");
}
感謝,
你不需要添加錯誤部分查看和設置Response.StatusCode = 500;你只需要在錯誤函數中得到返回數據的responseText屬性,就像在我的文章中一樣 – AEMLoviji 2011-04-14 06:20:33