【发布时间】:2015-04-15 03:51:34
【问题描述】:
我正在开发一个 C# MVC 应用程序。我有一个索引操作,它兼作 GET 和 POST 操作。在视图中,用户可以按项目名称或编号(或任何其他不同选项)进行搜索。
<tr>
<th>
Find by Name:
</th>
<th>
@Html.TextBox("NameSearchString", ViewBag.CurrentNameFilter as string)
</th>
<th>
<input type="submit" value="Search By Name" name="searchButton" />
</th>
</tr>
<tr>
<td></td>
</tr>
<tr>
<td></td>
</tr>
<tr>
<th>
Find by Project Number:
</th>
<th>
@Html.TextBox("NumberSearchString", ViewBag.CurrentNumberFilter as string)
</th>
<th>
<input type="submit" value="Search By Number" name="searchByNumber" />
</th>
</tr>
是否可以通过Request.Form检查Controller中“searchButton”的值?
在我目前拥有的控制器中:
// GET: PROJECTS
[AcceptVerbs(HttpVerbs.Get)]
public ActionResult Index(string sortOrder, string currentNameFilter, string currentNumberFilter, string nameSearchString, string numberSearchString, int? page,
string searchButton, bool? activeProjectsOnly = true)
{
当我单击“按名称搜索”按钮时,控制器中的“搜索按钮”字符串 =“按名称搜索”。这是意料之中的,但为什么我无法使用以下方法对其进行检查:
this.HttpContext.Request.Form["searchButton"]
这是 MVC 级别:
<dependentAssembly>
<assemblyIdentity name="System.Web.Mvc" />
<bindingRedirect oldVersion="0.0.0.0-5.2.2.0" newVersion="5.2.2.0" />
</dependentAssembly>
任何帮助将不胜感激。
【问题讨论】:
标签: c# asp.net-mvc asp.net-mvc-5