インデックスビューに2つの部分ビューを表示しようとしています。これらの部分ビューには、設定した検索ボックスで何かが検索されたときにデータを表示したいデータグリッドがあります。これらのページは両方とも別々に行うと機能しますが、部分的なビューとしてどのように使用するのかわかりません。
私の見解は次のようになります。
@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);
}
理想的には、その検索ボックスの内容が両方のビューに渡され、それに基づいてグリッドが形成されます。何が間違っているのかわからないので、助けていただければ幸いです。