【问题标题】:Unable to submit form data using Ajax.ActionLink inside a twitter bootstrap button dropdown无法在 twitter 引导按钮下拉列表中使用 Ajax.ActionLink 提交表单数据
【发布时间】:2014-01-09 16:30:29
【问题描述】:

我正在尝试提交一个搜索请求 (SEGQuery),该请求将根据用户从 twitter 引导按钮下拉列表 (SearchField) 中选择的内容来搜索特定字段。 SearchField 保存在查询字符串中,我在检索它时没有问题。但是,当我尝试发布 SEGQuery 时,它并没有发布到我的操作方法中,我不知道为什么。我正在尝试使用 Ajax.ActionLink 助手而不是按钮,因为我希望能够保持 twitter 引导下拉按钮的外观。

我遇到的另一个问题是,即使点击了 Action 方法,它也不会像应有的那样重定向到 SearchResults 视图。

是否有什么明显的错误导致我的模型数据无法正确发布?

查看

@using (Html.BeginForm("SearchResults", "SEG", FormMethod.Post))
{
<div class="seg-search">
    <div class="input-append">
        @Html.TextBoxFor(m => m.SEGQuery, new {@class = "input-large-seg"})
        <div class="btn-group">
            <button class="btn dropdown-toggle" data-toggle="dropdown">
                Search
                <span class="caret"></span>
            </button>
            <ul class="dropdown-menu">
                <li>@Ajax.ActionLink("Company Name", "SearchResults", new {fieldId = 1}, new AjaxOptions{HttpMethod = "POST"})</li>
                <li>@Ajax.ActionLink("FOM Code", "SearchResults", new {fieldId = 2}, new AjaxOptions{HttpMethod = "POST"})</li>
            </ul>
        </div>
    </div>
</div>
}

【问题讨论】:

    标签: asp.net ajax asp.net-mvc twitter-bootstrap


    【解决方案1】:

    如果我不明白您想要达到的目标,请纠正我:

    您想使用 Id SEGQuery 和下拉列表的选定值在文本框中发布值吗?

    一目了然,您缺少一个 type="submit"

    我的问题是 1. 为什么使用 ActionLink 作为下拉值 2. 为什么不在下拉列表下方有按钮 - 对用户更好

    我把代码改成

         @using (Html.BeginForm("SearchResults", "SEG", FormMethod.Post))
        {
        <div class="seg-search">
            <div class="input-append">
                @Html.TextBoxFor(m => m.SEGQuery, new {@class = "input-large-seg"})
                <div class="btn-group">                
                    <ul class="dropdown-menu">
                        <li>@Ajax.ActionLink("Company Name", "SearchResults", new {fieldId = 1}, new AjaxOptions{HttpMethod = "POST"})</li>
                        <li>@Ajax.ActionLink("FOM Code", "SearchResults", new {fieldId = 2}, new AjaxOptions{HttpMethod = "POST"})</li>
                    </ul>
    <button class="btn dropdown-toggle" type="submit" data-toggle="dropdown">
                        Search
                        <span class="caret"></span>
                    </button>
                </div>
            </div>
        </div>
        }
    

    【讨论】:

      猜你喜欢
      • 2021-12-29
      • 2018-06-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-08-29
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多