0

Is it possible to an call MVC action(Logout) from the jquery setTimeout function?

I have tried the following code:

setTimeout(function () { @Html.Action("Logout") }, 150000);
1
  • You can make an AJAX call to an MVC whatever and logout from there. Commented Apr 29, 2015 at 21:19

1 Answer 1

2

Do you understand the difference between when code runs?

This code:

setTimeout(function () { @Html.Action("Logout") }, 150000);

Will produce something like this on the client:

 setTimeout(function () { <div><a href="">Logout</a></div> }, 150000);

Which is completely invalid javascript (regardless what it actually does it will return html normally).

You could do (I think this is right)

 setTimeout(function () 
   { 
     window.location = '@Url.Action("Logout","Account")'; 
   }, 150000);

Which would produce something like:

 setTimeout(function () 
   { 
     window.location = '/Account/Logout'; 
   }, 150000);
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.