尝试在 ASP.NET 核心 MVC 中实现搜索时无法在控制器中获取文本框值
Failing to get textbox value in controller when trying to implement search in ASP.NET Core MVC
我正在尝试执行搜索,所以我有一个带有文本框的简单表单。我想将文本框的值传递给控制器,以便我可以开始搜索逻辑,但不幸的是,当我在控制器上放置断点时,我看到文本框中的字符串值为空,我不确定为什么。
我的表格:
<form method="get" asp-action="Search" >
<div class="input-group">
<input id="searchTerm" class="form-control" type ="text" @*asp-for="SearchTerm*@>
<div class="input-group-append">
<button class="btn btn-primary" type="submit">
Search
</button>
</div>
</div>
</form>
我的控制器:
public IActionResult Search(IFormCollection Form)
{
ViewBag.Name = Form["searchTerm"];
return View();
}
将表单方法更改为 post
并在输入标签中添加名称 属性
<input type="text" id="searchTerm" name="searchTerm" class="form-control" >
我正在尝试执行搜索,所以我有一个带有文本框的简单表单。我想将文本框的值传递给控制器,以便我可以开始搜索逻辑,但不幸的是,当我在控制器上放置断点时,我看到文本框中的字符串值为空,我不确定为什么。
我的表格:
<form method="get" asp-action="Search" >
<div class="input-group">
<input id="searchTerm" class="form-control" type ="text" @*asp-for="SearchTerm*@>
<div class="input-group-append">
<button class="btn btn-primary" type="submit">
Search
</button>
</div>
</div>
</form>
我的控制器:
public IActionResult Search(IFormCollection Form)
{
ViewBag.Name = Form["searchTerm"];
return View();
}
将表单方法更改为 post
并在输入标签中添加名称 属性
<input type="text" id="searchTerm" name="searchTerm" class="form-control" >