0

所以我有一个共享的布局。我想在该布局上有一个搜索表单。进行搜索时,我想将结果返回到灯箱中。我不是最擅长 JS 的。这是我所拥有的:

共享布局:

<div id="search-form">
@Html.Action("Search", "RespondentSearch")
</div>
<div id="search-results">
</div>

控制器:

[HttpGet]
[Whitelist]
public ActionResult Search()
{
     return PartialView("_SearchFormPartial");
}

[HttpPost]
[Whitelist]
public ActionResult Search(string query)
{
     return PartialView("_SearchResultsPartial");
}

搜索表单部分视图:

@using (Ajax.BeginForm("Search", "RespondentSearch", FormMethod.Post,
        new AjaxOptions
        {
            InsertionMode = InsertionMode.Replace,
            HttpMethod = "POST",
            UpdateTargetId = "search-results"
        },
        new
        {
            @class = "sidebarSearch"
        }
        ))
{
    <div>
        <input type="text" name="search" placeholder="respondent search..." id="ac" class="ui-autocomplete-input" autocomplete="off" />
        <span role="status" aria-live="polite" class="ui-helper-hidden-accessible"></span>
        <input type="submit" value="" rel="lightbox" />
    </div>
}

部分搜索结果:(整个表格就是我想要在 Lightbox 中出现的内容)

<table>
<tr>
<td>Stuff in Here</td>
</tr>
</table>
4

1 回答 1

1

我修好了它:

共享视图:

        <div id="RespondentSearch">
            @Html.Action("Search", "RespondentSearch")
        </div>

        <div id="search_results" style="display: none">
        </div>

控制器:

[HttpGet]
[Whitelist]
public ActionResult Search()
{
     return PartialView("_SearchFormPartial");
}

[HttpPost]
[Whitelist]
public ActionResult Search(string query)
{
     return PartialView("_SearchResultsPartial");
}

共享视图中的表单(一切的核心)

<div class="sidebarSearch">
    <input type="text" name="query" placeholder="respondent search..." id="ac" class="ui-autocomplete-input" autocomplete="off" />
    <span role="status" aria-live="polite" class="ui-helper-hidden-accessible"></span>
    <a href="#search_results" rel="lightbox" id="performSearch"></a>
</div>

<script>
    $('#performSearch').on('click', function () {
        $.ajax({
            url: "@(Url.Action("Search", "RespondentSearch"))",
            type: 'POST',
            data: { query: $('#query').val() },
            cache: false,
            async: true,
            success: function (result) {
                $("#search_results").html(result);
            }
        });
    });
</script>
于 2013-10-21T16:11:59.107 回答