Innovative Thinker
Innovative Thinker

Reputation: 1795

ASP.NET and Javascript not working in Firefox issue

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

Answers (2)

David Hoerster
David Hoerster

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

Alex
Alex

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

Related Questions