CmdrTallen
CmdrTallen

Reputation: 2282

Use RedirectToAction in a JsonResult Action?

using ASP.NET MVC 1.0 and I have a action that returns a JsonResult and I need to redirect another action that also returns a JsonResult action type.

The problem is the RedirectToAction() returns a RedirectToRouteResult class and seems there is no way to convert that to JsonResult class ?

This is the error I am getting; Error 124 Cannot implicitly convert type 'System.Web.Mvc.RedirectToRouteResult' to 'System.Web.Mvc.JsonResult'

Upvotes: 1

Views: 2749

Answers (1)

Tejs
Tejs

Reputation: 41246

So you have Action method A, which in some situation, needs to return the result from Action Method B?

Why not just do something like this:

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

public JsonResult ActionMethodB()
{
    // Something
}

Upvotes: 4

Related Questions