加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

asp.net-mvc – 具有相同签名的ASP.NET MVC 1.0控制器操作

发布时间:2020-12-16 06:35:53 所属栏目:asp.Net 来源:网络整理
导读:所以基本上在我的UserController.cs类中,我有一个Index方法,它返回ActionResult以显示用户的仪表板.在这个页面上是一个带有提交类型的html按钮.当我点击此按钮时,我想在服务器端捕获它,将用户输出. 我怎么能这样做,因为我没有传回信息,方法签名最终是相同的.
所以基本上在我的UserController.cs类中,我有一个Index方法,它返回ActionResult以显示用户的仪表板.在这个页面上是一个带有提交类型的html按钮.当我点击此按钮时,我想在服务器端捕获它,将用户输出.

我怎么能这样做,因为我没有传回信息,方法签名最终是相同的.

谢谢,

麦克风

[Authorize]
    public ActionResult Index()
    {
        return View();
    }

    [Authorize]
    [AcceptVerbs(HttpVerbs.Post)]
    public ActionResult Index()
    {
        FormsAuthentication.SignOut();
        return RedirectToAction("Index","Home");
    }

解决方法

使用:

[Authorize]
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Index(FormCollection values)
{
    FormsAuthentication.SignOut();
    return RedirectToAction("Index","Home");
}

要么

[Authorize]
[AcceptVerbs(HttpVerbs.Post),ActionName("Post")]
public ActionResult IndexPost()
{
    FormsAuthentication.SignOut();
    return RedirectToAction("Index","Home");
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读