您可能要實現自定義的替換功能
1)建立一個響應模式,將包含相應信息
public class ReposnseModel
{
public bool isSuccess {get; set;}
public string SuccessMessage {get;set;}
public string ErrorMessage {get;set;}
}
您迴應的狀態
2)您的表單必須通過局部視圖呈現,因此您只能返回其內容
public ActionResult DoWork(Model model)
{
//if success:
...
return Json(new ReposnseModel{isSuccess = true, SuccessMessage = "Success"});
//if lets say model is not valid or some other error:
return PartialView("YourPartialViewForm",model)
}
註冊Ajax.BeginForm的onSuccess回調像這樣的東西:
function Callback(data) {
if (data != null) {
if (data.isSuccess != undefined) { //means that the data is a serialized ReposnseModel and not a form content
if (data.isSuccess) {
alert(data.SuccessMessage);
}else
{
alert(data.ErrorMessage);
}
}
else { //otherwise data is a form content, so it needs to replace the current content
$('#formContainer').html(data);
}
}
}
演出便代碼:) – 2014-12-05 20:18:13
我可以的,如果你真的需要它,但它的所有加工。我沒有問題,但只是一個問題:-) – PoeHaH 2014-12-05 20:19:30