使用ASP.NET MVC 1.0,我有一个返回JSONRESULT的操作,我需要重定向另一个动作,该操作还返回JSONRESULT ACTION类型。

问题是RedirectToAction()返回RedirectTorouteresult类,似乎没有办法将其转换为JSONRESULT类?

这是我遇到的错误;错误124不能隐式转换类型'system.web.mvc.redirecttorouteresult'为'system.web.mvc.jsonresult'

有帮助吗?

解决方案

因此,您有动作方法A,在某些情况下需要从动作方法B返回结果?

为什么不做这样的事情:

public JsonResult ActionMethodA()
{
     if(someCondition)
        return ActionMethodB();
     else
        return new JsonResult();
}

public JsonResult ActionMethodB()
{
    // Something
}
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top