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


how can redirect action jsonresult actionresult m getting error. error "cannot implicitly convert type 'system.web.mvc.redirecttorouteresult' 'system.web.mvc.jsonresult'". 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);         }     } 

you need use base class actionresult can return view,json,content or partial view:

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);    } 

but if calling action via ajax have redirect action via javascript because returning redirecttoaction return html in response of ajax not redirect.

so need return action url via json flag , check if response has flag, redirect url via jquery.

in ajax call success check if url:

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

Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -