Hỏi đáp

Chia sẻ kiến thức, cùng nhau phát triển

Cách dùng Của Href và @Html.ActionLink trong ASP.NET MVC

12:58 13-06-2017 9.766 lượt xem 4 bình luận 17:12 31-01-2018

@Html.ActionLink là cách dùng của <a href="/redirect?Id=RLX%2f%2ftLSCasuwp2suFtwEaXwEkbkacey9O9VxDdN97LXNoOZwhtx%2fIHx8ARoptaaT3IXmjU8uFlm012bAGZ8FQ%3d%3d" ASP.NET

Ví dụ em muốn tạo button đăng nhập khi ấn vào thì sẽ ra một page mới để điền thông tin:

<button href="/redirect?Id=Ok7QNCdcSHCUf3tyR7o94w%3d%3d" type="button" class="btn btn-sm btn-info">Đăng nhập</button>

thì làm sao để áp dụng được cái @Html.ActionLink ạ?
@Html.ActionLink("Đăng nhập", "Acount", "Acount")

Bình luận

Để bình luận, bạn cần đăng nhập bằng tài khoản Howkteam.

Đăng nhập
Vinh đã bình luận 17:12 31-01-2018

Em thì chơi hỗn hợp luôn. Vừa a href vừa ActionLink

<ul>
                <li class="menu-dropdown">
                    <a href="#" class="menu-dropbtn">Ngôn Ngữ IT</a>
                    <div class="menu-dropdown-content">
                        @Html.ActionLink("C-Sharp", "CSharp", "ITLang")
                        @Html.ActionLink("Pascal", "Pascal", "ITLang")
                        @Html.ActionLink("VB .NET", "VBNet", "ITLang")
                    </div>
                </li>

</ul>

Em tự tạo cái CSS cho thanh menu như sau:

* {
    margin: 0px;
    padding: 0px;
}

/*Thanh menu Home*/
.menu {
    width: 100%;
    min-width: inherit;
    top: 0px;
    position:relative;
    z-index: 1;
}

    .menu ul {
        list-style-type: none;
        margin: 0;
        padding: 0;
        overflow: hidden;
        background-color: black;
        align-content: center;
    }

        .menu ul li {
            float: left;
        }

            .menu ul li a, .menu-dropbtn {
                display: block;
                color: #ffffff;
                text-align: left;
                padding: 14px 16px;
                text-decoration: none;
            }

                .menu ul li a:hover, .menu-dropdown:hover .menu-dropbtn {
                    background-color: red;
                }

            .menu ul li.dropdown {
                display: inline-block;
            }

.menu-dropdown-content {
    display: none;
    position: absolute;
    background-color: #808080;
    min-width: 180px;
    box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
    z-index: 1;
}

    .menu-dropdown-content a {
        color: black;
        padding: 12px 16px;
        text-decoration: none;
        display: block;
        text-align: left;
    }

        .menu-dropdown-content a:hover {
            background-color: #f1f1f1
        }

.menu-dropdown:hover .menu-dropdown-content {
    display: block;
}

 

hoangitc500 đã bình luận 09:34 14-06-2017

Em cảm ơn ạ!
À em có thêm câu muốn hỏi nữa ạ?

<li class="dropdown">
                        <a class="dropdown-toggle" data-toggle="dropdown">Phần mềm<span class="caret"></span></a>
                        <ul class="dropdown-menu" role="menu">
                            <li>@Html.ActionLink("Window", "Window", "Software")</li>
                            <li>@Html.ActionLink("Office", "Office", "Software")</li>
                            <li>@Html.ActionLink("Anti-virus", "Antivirus", "Software")</li>
                            <li>@Html.ActionLink("Phần mềm khác", "OtherSoftware", "Software")</li>
                        </ul>
                    </li>

có cách nào để mình chèn link vào chữ Phần mềm không ạ? Em để @Html.ActionLink thì nó toàn bị thụt xuống với không hiện được Dropdown ạ?

K9 SuperAdmin, KquizAdmin, KquizAuthor đã bình luận 03:10 14-06-2017

Với button thì bạn phải dùng form nhé

Và mình nhớ là Input type là button mà đúng k nhỉ

@using (Html.BeginForm("someAction", "someController"))
{
    <button type="submit">OK</button>
}

 

Có cách cheat từ link thành hình button như sau

<%= Html.ActionLink("Button Name", "Index", null, new { @class="classname" }) %>
a.classname
{
    background: url(../Images/image.gif) no-repeat top left;
     display: block;
     width: 150px;
     height: 150px;
     text-indent: -9999px; /* hides the link text */
}

 

Câu hỏi mới nhất