【问题标题】:Trying to trigger postback on MVC dropdownlist in VB .net尝试在 VB .net 中触发 MVC 下拉列表的回发
【发布时间】:2013-10-24 16:14:06
【问题描述】:

这是我在 SearchResults 视图中用于颜色下拉列表的代码

<td>@Html.DropDownList("colours", TryCast(ViewData("colours"), SelectList),
                       New With {.onchange = "document.getElementById('wineSearchCriteria').submit();"})</td>

我已将表单名称设置为“wineSearchCriteria”

<form action="/Wines/SearchResults" method="post" name="wineSearchCriteria"
    input type="submit" value="Search"/>

但是当颜色下拉列表更改时,表单不会发回。我相信这会很简单!

【问题讨论】:

  • 只是一些信息。 postback 在很大程度上是一个 Webforms 概念。 MVC 与 HTTP 的耦合更紧密,因此它可以是 POSTGET

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


【解决方案1】:

document.getElementById() 只会通过 ID 检索元素,但您不会为表单分配 ID。您正在为表单指定一个名称。请改用id 属性:

<form action="/Wines/SearchResults" method="post" id="wineSearchCriteria"
input type="submit" value="Search"/>

【讨论】:

  • 谢谢查理 - 正如我所说,我知道它必须是简单的!感谢您的回复。
【解决方案2】:

您应该将 id 属性设置为"wineSearchCriteria",而不是名称。

<form action="/Wines/SearchResults" method="post" id="wineSearchCriteria" />

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-08-09
    相关资源
    最近更新 更多