Question

In MVC4, I am trying to use the one controller method in another controller method using RedirectToAction but it shows error while try to receive the returned value of other controller's method.

I have following controller method:

public class TranslationController : Controller
{
   public ActionResult Search_Query()
   {
        List<Surah> Records = new List<Surah>();
        Records = RedirectToAction(" Load_Surahs", "Surah_CRUD");
        ...
        return Json(new { key = Records }, JsonRequestBehavior.AllowGet);
   }
}

Another controller method:

public class Surah_CRUDController : Controller
{
   public ActionResult Load_Surahs() 
    {
         List<Surah> Records = new List<Surah>();
         ...
         return Json(new { key = Records }, JsonRequestBehavior.AllowGet);
    }
}

how to fix it, i mean i want to use Load_Surahs returned list of objects in Search_Query method...

No correct solution

OTHER TIPS

Place method GetSurah in separate service.And use this service in both controllers.

public class TranslationController : Controller
{
   public ActionResult Search_Query()
   {
       List<Surah> Records = someService.GetSurah();
       ...
       return Json(new { key = Records }, JsonRequestBehavior.AllowGet);
   }
}


public class Surah_CRUDController : Controller
{
   public ActionResult Load_Surahs() 
    {
         List<Surah> Records = someService.GetSurah();
         ...
         return Json(new { key = Records }, JsonRequestBehavior.AllowGet);
    }
}

Change the code to:

public ActionResult Load_Surahs() 
        {
             List<Surah> Records = new List<Surah>();
             ...               

             return RedirectToaction("Search_Query","TranslationController ", 
                                      new {jsData = "Your Json data here" });
        }

And in your other action use

public ActionResult Search_Query(Json jsData)
        {

        }

Change the return type of Load_Surahs() to JsonResult

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top