没有Java脚本的DropDownList中是否有Html.ActionLink? [英] is it posible do have Html.ActionLink inside a DropDownList Without java script?

查看:42
本文介绍了没有Java脚本的DropDownList中是否有Html.ActionLink?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可能有类似的东西?

Is it possible to have something like this?

@Html.DropDownListFor(
                @Html.ActionLink("About", "About", "Home")
                @Html.ActionLink("mypage","index","Home")
                @Html.ActionLink("apage","anypage","Home")

                @Html.ActionLink("Test","Test","home")
                @Html.ActionLink("pagetest", "tsetPage", "Home")
                );

推荐答案

否,没有javascript,这是不可能的.尤其是如果用户希望用户在此下拉列表中选择一个项目后,便希望页面导航到相应的地址.如果您不想使用javascript,则可以将下拉列表放在HTML <form>内,但用户必须单击提交"按钮才能进行导航.这是一个示例,您可以使用javascript实现此目标:

No, this is not possible without javascript. Especially if you want the page to navigate to the corresponding address once the user selects an item in this dropdown. If you don't want to use javascript you could place the dropdown inside an HTML <form> but then the user will have to click on the submit button in order to navigate. Here's an example how you could achieve this with javascript:

@Html.DropDownList(
    "url",
    new SelectList(new[]
    {
        new SelectListItem { Text = "About", Value = Url.Action("About", "Home") },
        new SelectListItem { Text = "MyPage", Value = Url.Action("Index", "Home") },
        new SelectListItem { Text = "APage", Value = Url.Action("AnyPage", "Home") },
    }, "Value", "Text"),
    "-- Pick an URL ---",
    new { id = "urlddl" }
)

然后使用jquery,您可以订阅此下拉列表的change事件并导航到相应的URL:

and then using jquery you could subscribe for the change event of this dropdownlist and navigate to the corresponding url:

$(function() {
    $('#urlddl').change(function() {
        var url = $(this).val();
        if (url != null && url != '') {
            window.location.href = url;
        }
    });
});

这篇关于没有Java脚本的DropDownList中是否有Html.ActionLink?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆