您可能要实现自定义的替换功能
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