return通常从方法返回而无需执行任何其他语句,因此
else不需要。这样,您将摆脱问题#1。
至于重定向,为什么不返回某种 重定向 命令:
[HttpPost]public ActionResult Index(LoginModel loginData){ if (login fails) { return Json(new {result = "InvalidLogin"}, JsonRequestBehavior.AllowGet); } return Json(new {result = "Redirect", url = Url.Action("MyAction", "MyController")});}然后在javascript中:
$.post(url, data, function (response) { if (response.result == 'InvalidLogin') { //show invalid login } else if (response.result == 'Error') { //show error } else if (response.result == 'Redirect'){ //redirecting to main page from here for the time being. window.location = response.url; } });


