所以我有一个共享布局。我希望在该布局上有一个搜索表单。搜索完成后,我想将结果返回到灯箱中。我不是最好的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");
}
SearchFormPartial查看:
@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>
答案 0 :(得分: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>