【问题标题】:How to put two href links in an If statement?如何在 If 语句中放置两个 href 链接?
【发布时间】:2019-02-17 16:04:05
【问题描述】:

如果请求通过身份验证,我希望登录和创建帐户链接显示为“登录/创建帐户”,同时作为指向其相关页面的链接。

我在 else 部分遇到错误。如何重新编写它以消除错误并以我想要的方式显示链接?

 <div class="float-right">
                <div class="user-option">
                    <span class="icon icon-avatar"></span>
                    @if (Request.IsAuthenticated)
                    {
                        <a href="/account/logout">Logout</a>
                    }
                    else
                    {
                   <a href="/account/login">Login</a>  /  <a href = "/account/create-account" > Signup </a>;

                    }


                </div>
            </div>

【问题讨论】:

    标签: html asp.net asp.net-mvc


    【解决方案1】:

    您遇到的问题是斜线。它不在任何 html 标记内。快速解决方法是将其包装在 span 中。

        <a href="/account/login">Login</a> <span>/</span> <a href = "/account/create-account"> Signup </a>
    

    更正确的方法是将链接放在无序列表中,并使用 CSS 来格式化。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-09-16
      • 1970-01-01
      • 2012-09-07
      • 1970-01-01
      • 2014-05-04
      • 1970-01-01
      相关资源
      最近更新 更多