前提・実現したいこと
データベースに接続して取得したデータを部分ビューとして表示したいです。
発生している問題・エラーメッセージ
現在、検索項目を指定して検索ボタンを押すと、ページ遷移して次のページにデータベースから取得したデータを貼り付けてしまいます。本来であれば、検索ボ項目を指定する同じページの余白に出力したいと考えています。
エラーメッセージ
エラーはなく、別のページに遷移して出力しています。
該当のソースコード
@{ ViewData["Title"] = "リポジトリ検索"; } @model Search <form asp-action="Index" asp-controller="Search" method="post"> <div class="col-md-6"> <label asp-for="GyoshuMei"></label> @{ var industories = ViewBag.Industories; var industoryList = new List<SelectListItem>(); foreach (var c in industories) { var s = new SelectListItem(); s.Text = c.GyoshuMei.ToString(); s.Value = c.GyoshuMei.ToString(); industoryList.Add(s); } } @Html.DropDownListFor(model => model.GyoshuMei, industoryList, "全件") </div> <br /> <br /> <div class="col-md-12"> <label asp-for="SystemMei"></label> @{ var systemTypes = ViewBag.SystemTypes; var systemTypeList = new List<SelectListItem>(); foreach (var c in systemTypes) { var s = new SelectListItem(); s.Text = c.SystemMei.ToString(); s.Value = c.SystemKB.ToString(); systemTypeList.Add(s); } } @Html.DropDownListFor(model => model.SystemKB, systemTypeList, "全件") </div> <br /> <br /> <div class="col-md-12"> <label for="keyword">キーワード</label> @Html.TextBoxFor(model => model.Keyword1) @Html.TextBoxFor(model => model.Keyword2) @Html.TextBoxFor(model => model.Keyword3) @Html.RadioButtonFor(model => model.OnTypeChanged, 0, new { @id = "AND" })AND @Html.RadioButtonFor(model => model.OnTypeChanged, 1, new { @id = "OR" })OR </div> <br /> <div> <input id="search" type="submit" value="検索"> </div> <br /> <br /> <br /> @Html.PartialAsync("_SearchResult") </form>
using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Threading.Tasks; using Microsoft.AspNetCore.Mvc; using WebApplication3.Models; using WebApplication3.Modules; namespace WebApplication3.Controllers { public class SearchController : Controller { mdlCommon mdlCmn = new mdlCommon(); [HttpGet] public IActionResult Index() { List<Search> industoryList = new List<Search>(); industoryList = mdlCmn.GetGyoshu(); ViewBag.Industories = industoryList; List<Search> systemTypeList = new List<Search>(); systemTypeList = mdlCmn.GetSystemTypes(); ViewBag.SystemTypes = systemTypeList; return View(); } [HttpPost] [ValidateAntiForgeryToken] public IActionResult Index(Search search) { List<Search> results = new List<Search>(); results = mdlCmn.GetResult(search); ViewBag.SearchResults = results; return PartialView("_SearchResult", results); } }
試したこと
補足情報(FW/ツールのバージョンなど)
VS2019
ASP.NET Core MVC
Core Version 3.1.1
回答2件
あなたの回答
tips
プレビュー