【发布时间】:2016-03-15 16:54:42
【问题描述】:
我遇到需要返回 JSONResult 或重定向的情况。 有可能吗?
例子:
public ActionResult Example(string code)
{
if(string.IsNullorEmpty(code))
return RedirectToAction("Index", "Home");
else
return Json(new { success = true, message= "Next step"});
}
【问题讨论】:
-
是的,两者都可以返回,因为它们是
ActionResults。但是,如果您在 Ajax 调用中返回RedirectToAction,它将不会重定向。这是你的问题吗?
标签: c# asp.net-mvc redirect model-view-controller jsonresult