Cannot implicitly convert type 'System.Web.Mvc.RedirectToRouteResult' to 'System.Web.Mvc.JsonResult'

How can I redirect to an action from JsonResult to ActionResult, but I get an error. my error is: "It is not possible to implicitly convert the type" System.Web.Mvc.RedirectToRouteResult "to" System.Web.Mvc.JsonResult ". My code

Json Result:

   public JsonResult AddTruckExpensesTransactionChild(string totaldays, string amount)
   {
        string Mess = objActive.Save();
        if (Mess == "1")
        {
            return RedirectToAction("GetTruckExpensesChild", new { id="", sid="" });
        }
        return Json(Mess, JsonRequestBehavior.AllowGet);
   }

ActionResult:

    public ActionResult GetTruckExpensesChild(string id, string sid)
    {
        TruckExpensesTransactionClass Transaction = new TruckExpensesTransactionClass();
        if (sid != null)
        {                
            Transaction.TransactionChild = objActive.ShowTransactionChild(id, sid);
            return View(Transaction);
        }
        else
        {                
            return View(Transaction);
        }
    }
+4
source share
2 answers

ActionResult, , JSON, :

public ActionResult AddTruckExpensesTransactionChild(string totaldays, string amount)
   {
        string Mess = objActive.Save();
        if (Mess == "1")
              return Json(new { Url = Url.Action("GetTruckExpensesChild", new { id = "", sid = "" }) });

        return Json(Mess, JsonRequestBehavior.AllowGet);
   }

ajax, javascript, RedirectToAction html ajax, .

, URL- json , , URL jquery.

Ajax call success , url:

success: function(result) {
          if(result.Url.length > 0)
{
        window.location.href=result.Url;
}
+4

JsonResult ActionResult. JsonResult ActionResult :

public ActionResult AddTruckExpensesTransactionChild(string totaldays, string amount)
{
    string Mess = objActive.Save();
    if (Mess == "1")
    {
        return RedirectToAction("GetTruckExpensesChild", new { id="", sid="" });
    }
    return Json(Mess, JsonRequestBehavior.AllowGet);
}
+3

Source: https://habr.com/ru/post/1543007/


All Articles