Asp.net mvc key=value asp.net mvc与url get?

Asp.net mvc key=value asp.net mvc与url get?,asp.net-mvc,url,key-value,Asp.net Mvc,Url,Key Value,给你一个小问题 在母版页中,我有一个搜索输入和链接: <input type="text" value="Searche..." name="txtSearche" id="txtSearche" style="vertical-align: middle; height:14px;" /> <%= Html.ActionLink("search", "Search", "Search", new{ searche = "txtSearche???what is here"},

给你一个小问题

在母版页中,我有一个搜索输入和链接:

<input type="text" value="Searche..." name="txtSearche" id="txtSearche" style="vertical-align: middle; height:14px;" />
<%= Html.ActionLink("search", "Search", "Search", new{ searche = "txtSearche???what is here"}, null) %>
我最大的问题是这里->新建{search=“txtSearche???这里是什么”} 我不知道如何使这部分工作

public ActionResult Search(string txtSearche, string searche) {
简单:)只需将其放入参数中

或者您也可以执行
stringsearche=Request[“searche”]
但在MVC中,使用第一个选项:)

编辑:好的,我得到你想要的。你有一个输入表单,你想使用它

2个词:使用POST

您正试图在URL中发出get请求,实际上是POST请求。发表一篇文章,然后在返回视图中,也可以在URL中进行查询

最好的办法是进行回发,它将返回导航到新的URL,其中包含搜索查询

return RedirectToAction("Search", new { searche = txtSearche });

如果您希望获得文本框输入,那么您需要将其放入带有提交按钮的表单中。然后您将捕获“TXTSearch”:



不过,您需要让您的操作接受
[HttpPost]
。除非您让表单使用GET方法,否则我的html.actionlink中的{search=“txtsearch”}是新的吗?看,您的问题一点也不清楚。你想要什么?:)你想在你的控制器里或者在你的页面里找到答案吗?
return RedirectToAction("Search", new { searche = txtSearche });
<% using(Html.BeginForm()) { %>
  <input type="text" value="Searche..." name="txtSearche" id="txtSearche" style="vertical-align: middle; height:14px;" />
  <input type="submit" value="search" />
<% } %>