我试图在我的索引视图中显示两个部分视图。在这些部分视图中是数据网格,当在我设置的搜索框中搜索某些内容时,我想显示数据。这两个页面在我单独执行时都可以工作,但我不知道如何将它们用作局部视图。
我的视图如下所示:
@using (Html.BeginForm("Index", "Home", "POST"))
{
<div class="searchField">
<div class="searchbox">
Search: <input type="text" name="heatSearch" />
<input type="submit" value="Submit">
</div>
</div>
}
<div>
@Html.Partial("PartialChemAnalysis", (string)ViewBag.SearchKey)
</div>
@Html.Partial("PartialSlag", (string)ViewBag.SearchKey)
我的控制器看起来像这样:
public class HomeController : Controller
{
public ActionResult Index()
{
return View();
}
[HttpPost]
public ActionResult Index(string heatSearch)
{
ViewBag.SearchKey = heatSearch;
return View();
}
public ActionResult PartialChemAnalysis(string heatSearch)
{
HomeModel C = new HomeModel();
IEnumerable<HomeModel> model = C.ChemList;
C.ChemistryDataPull(heatSearch);
return PartialView(C.ChemList);
}
public ActionResult PartialSlagView(string heatSearch)
{
PartialSlagViewModel D = new PartialSlagViewModel();
IEnumerable<PartialSlagViewModel> model = D.SlagList;
D.SlagViewDataPull(heatSearch);
return PartialView(D.SlagList);
}
理想情况下,该搜索框中的内容将传递给两个视图,并且网格将基于此形成。我不确定我做错了什么,因此感谢您的帮助。