早上好,我有一个局部视图-在Home控制器中,它允许用户输入文本并查找匹配/包含文本的地方
我当前的代码:
@using (Html.BeginForm("_PartialSearch", "Home", FormMethod.Post))
{
<form id="form-search" class="ng-pristine ng-valid">
<div class="input-search">
<input type="text" name="txtSearch" data-ng-model="textSearch" auto-complete="" placeholder="Search for places..." name="q" id="input-search" class="ng-pristine ng-untouched ng-valid ui-autocomplete-input" autocomplete="off">
<a class="btn-search" href="#">
<span class="fa fa-search"></span>
</a>
<div class="list-search-result hidden" id="search-result">
<!-- ngIf: isLoading -->
<!-- ngIf: datas.length>0 -->
<!-- ngIf: datas.length===0 -->
</div>
</div>
</form>
}
在调用操作_PartialSearch的Home Controller中:
[HttpPost]
public ActionResult _PartialSearch(string txtSearch)
{
var ListPlaces = db.PLACES.ToList();
if (String.IsNullOrEmpty(txtSearch))
{
ViewBag.txtSearch = txtSearch;
ListPlaces = db.PLACES.ToList();
}
else
{
ViewBag.txtSearch = txtSearch;
ListPlaces = db.PLACES.Where(x => x.PLACENAME.Contains(txtSearch.ToString())).ToList();
}
return View("../SearchResult/Index", ListPlaces );
}
我遇到的问题是如何将数据传递到控制器SearchResult的ActionResult索引?
在SearchResult Controller和视图中
public ActionResult Index(IEnumerable<PLACES> places)
{
return View(places);
}