注销按钮不起作用
本文关键字:不起作用 按钮 注销 | 更新日期: 2023-09-27 18:02:20
我有一个注销按钮,当我尝试在我的应用程序上单击注销时,它显示了这个消息,这里是我得到的消息
参数字典包含的参数'id'为空条目非空类型。Int32' for方法'System.Web.Mvc.ActionResult LogOff(Int32)' in"Web_Site_Portal.Controllers.AccountController"。一个可选的参数必须是引用类型、可空类型,或者声明为可选参数。参数名称:parameters
这是我的代码
<a class="btn btn-primary btn-raised" @Html.ActionLink("Logout", "LogOff", "Account", routeValues: null, htmlAttributes: new { id = "logOff" })<div class="ripple-container"></div></a>
控制器// POST: /Account/LogOff
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult LogOff()
{
AuthenticationManager.SignOut(DefaultAuthenticationTypes.ApplicationCookie);
return RedirectToAction("Index", "Home");
}
//
// POST: /Account/LogOff
[HttpGet]
public ActionResult LogOff(int id)
{
AuthenticationManager.SignOut(DefaultAuthenticationTypes.ApplicationCookie);
return RedirectToAction("Index", "Home");
}
您在LogOff
操作中有一个int
参数,这似乎是错误的。您不需要此参数,因为您正在注销当前登录的用户。我看到你的LogOff链接有一个id
路由参数,它是一个字符串。为什么呢?如果需要,必须将LogOff
动作的参数类型更改为字符串。
编辑
你有两个做同样事情的动作。如果您希望LogOff操作同时与GET
和POST
方法一起工作,那么从操作中删除[HttpGet]
和[HttpPost]
。你只需要:
public ActionResult LogOff()
{
AuthenticationManager.SignOut(DefaultAuthenticationTypes.ApplicationCookie);
return RedirectToAction("Index", "Home");
}