【问题标题】:create manually parameter ReturnUrl手动创建参数 ReturnUrl
【发布时间】:2010-03-17 02:10:25
【问题描述】:

我有像'home/details/5'这样的视图,它可以被匿名用户访问。但是有按钮,只有注册用户才能按下。没问题,我可以查看 Request.IsAuthenticated ,如果匿名我显示按钮登录而不是秘密按钮

但是问题-当按下登录时,我可能会丢失页面的地址和参数。如何创建登录按钮并传递参数 ReturnUrl ?像

 <%= Html.ActionLink("enter to buy", "LogOn", "Account", new { ReturnUrl = path to view with route value })%>

我只看到愚蠢的解决方案

<%= Html.ActionLink("enter to buy", "LogOn", "Account", new { ReturnUrl = "home/details/" + ViewContext.RouteData.Values["id"] })%>

但我不喜欢硬编码控制器的名称

【问题讨论】:

    标签: asp.net-mvc returnurl


    【解决方案1】:

    您也可以使用Request.Url.AbsolutePath

    <%= Html.ActionLink("enter to buy", "LogOn", "Account", 
        new { ReturnUrl = Request.Url.AbsolutePath })%>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-08-22
      • 1970-01-01
      • 2015-10-18
      • 2013-09-07
      • 2020-01-17
      • 1970-01-01
      • 1970-01-01
      • 2014-12-16
      相关资源
      最近更新 更多