【问题标题】:Page redirection when changing value in dropdown list更改下拉列表中的值时的页面重定向
【发布时间】:2011-08-11 19:53:33
【问题描述】:

我有以下代码可以创建一个下拉列表。
当用户选择一个项目时,我想在控制器中调用某个操作并将新值作为参数传递。

我有以下代码,但这不起作用,当我检查 Firebug 时,我得到“无效的正则表达式 C”。

            @Html.DropDownList(
                "ctrlName", 
                items, 
                null,
                new { onchange = "document.location.href = /Controller/Action/this.options[this.selectedIndex].value;" })

【问题讨论】:

    标签: asp.net-mvc-3


    【解决方案1】:

    你在 js 中缺少引号

    @Html.DropDownList(
        "ctrlName", 
        items, 
        null,
        new { onchange = "document.location.href = '/Controller/Action/' + this.options[this.selectedIndex].value;" })
    

    【讨论】:

    【解决方案2】:
    <%:Html.DropDownList("ctrlName", new[]{
        new SelectListItem { Text="--Select--", Value="" },
        new SelectListItem { Text = "KodefuGuru", Value = "Create" }, 
        new SelectListItem { Text = "PlatinumBay", Value = "PlatinumBay" }
        },
        null,
        new { onchange = "document.location.href = '/Controller/Action/'+this.options[this.selectedIndex].value;)" })%>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-10-24
      • 1970-01-01
      • 1970-01-01
      • 2012-10-22
      • 2015-05-12
      • 1970-01-01
      • 1970-01-01
      • 2019-01-01
      相关资源
      最近更新 更多