Reputation: 1795
I have problem with javascript code inside my controller. The below code working fine with all the browser(IE,Chrome and Safari) but not in Firefox? It prints the javascript code in the browser. Please help me anyone had the same issue. Thanks in advance.
public ActionResult LogOut()
{
System.Text.StringBuilder sb = new System.Text.StringBuilder();
sb.Append("<script type = 'text/javascript'>");
sb.Append("window.location.href = 'myurl'");
sb.Append("</script>");
return JavaScript(sb.ToString());
}
If any other way to do this please share with me.
Upvotes: 0
Views: 484
Reputation: 28711
Why not just use a Redirect action result to redirect the user to myurl
?
Get rid of the StringBuilder
logic and just:
return RedirectToAction(yourAction);
if it's an action in the same controller, or:
return Redirect('myurl');
if it's an URL outside the controller.
Upvotes: 1
Reputation: 1687
Try returning Content instead of JavaScript:
return Content(sb.ToString());
But if you just need to redirect users, then it's better to use redirect:
return Redirect("myurl");
Upvotes: 0