简体   繁体   中英

How to call a Controller ActionResult method from @Html.ActionLink

I want to call a controller ActionResult method from anchor tag without changing the url in MVC3 razor engine.

My url is: "http://localhost:2993/admin/adminindex" and I have one anchor tag "SingOut" and i want to remove my session.

This is my syntax on View page:

<div>@Html.ActionLink("SingOut", "signout", "Admin")</div>

And on Admincontroller I want to call this ActionResult method

public ActionResult signout()
{
      Session.Abandon();
      return View("~/Views/admin/admin.cshtml");         
}

When I click on signout, it always goes to Index ActionResult method. Is it Possible to call Controller ActionResult method from javascrit not jquery? I want it only pure javascript not jquery.

Abandoning the session will most likely cause a redirect to the index page. The page you are viewing is protected (as far as i understand) so when you sign out you cant stay on the same page. Then why would you do it asynch if the system is redirecting you anyway (or worse you are logged out and showing a page that doesnt work) ?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM