这是我的ajax电话
$.ajax({
type: "POST",
url: "MyMethod",
contentType: 'application/json; charset=utf-8',
data: JSON.stringify({ Param1: 'value1', Param2: 'value2'}),
success: function (msg) { location.href = '@Url.Action("MyActionMethod", "MyController")'; },
error: function (msg) { alert(msg); }
});
这是我的模特
public class MyModel
{
public string Param1 { get; set; }
public string Param2 { get; set; }
}
MyMethod实现如下
public bool MyMethod(MyModel model)
{
if (!ValidateModel(model) )
{
// I want to error a descriptive error
return false;
}
// Some other processing
return true;
}
问题是我不知道它是如何确定呼叫是成功还是失败的。返回ture / false似乎没有帮助,因为代码总是进入成功代码路径(即它重定向到MyController.MyActionMethod)。任何想法我做错了