c# - How to redirect from controller using RedirectToAction method -


i trying redirect controller action controller action below:

public class logincontroller : controller {      public actionresult index()     {         return view();     }      public actionresult redirecttoregister()     {         return redirecttoaction("index", "register");     }  }  public class registercontroller : controller {      public actionresult index()     {         return view();     }  } 

i have url in cshtml page below:

<script type="text/javascript">     var loginredirecttoregisterurl = '@url.action("redirecttoregister", "login")'; </script> 

and calling js below:

function callredirecttoregister() {     window.location = loginredirecttoregisterurl; } 

but not redirecting me register page. routing below:

public static void registerroutes(routecollection routes) {     routes.ignoreroute("{resource}.axd/{*pathinfo}");      routes.maproute(         name: "default",         url: "{controller}/{action}/{id}",         defaults: new { controller = "login", action = "index", id = urlparameter.optional }     ); } 

where doing wrong?

the server-side redirection looks fine, client-side call not much: $.post(loginredirecttoregisterurl); starts ajax call url. not change current page. use this:

function callredirecttoregister() {     window.location = loginredirecttoregisterurl; } 

this issue http request. need remove [httppost] attribute action work. if can't have put html form on page , submit post request. this:

function callredirecttoregister() {     $('<form id="redirectform">').attr('method', 'post').attr('action', loginredirecttoregisterurl).appendto($('body')).submit(); } 

Comments

Popular posts from this blog

python - No exponential form of the z-axis in matplotlib-3D-plots -

php - Best Light server (Linux + Web server + Database) for Raspberry Pi -

c# - "Newtonsoft.Json.JsonSerializationException unable to find constructor to use for types" error when deserializing class -