[英]Asp.net mvc 2 Search form in Partial View
嗨,有人可以為我做一個小例子。
我想創建一個帶有文本框和提交按鈕的局部視圖。 當用戶點擊“提交”按鈕時,我想重定向到以下網址
/搜索/ SEARCHQUERY /
UPDATE
//這是我的searchBox.ascx
<% using (Html.BeginForm("Index", "Search", new { area = "eCommerce" }, FormMethod.Post, new { searchTerm = "searchTerm" })) %>
<% { %>
<input name="searchTerm" type="search" results="5" placeholder="Product search" autofocus />
<input type="submit" value="Search">
<% } %>
這是我的SearchController
public string Index(string searchTerm)
{
return "your search term was "+ searchTerm;
}
最后是我的MapRoute
context.MapRoute(
"Search",
"Search/{searchTerm}/",
new { controller = "Search", action = "Index", searchTerm = UrlParameter.Optional }
);
現在可以使用/ Search / searcTerm /了,但是當我使用searchBox時,它只是重定向/ Search,但是我的SearchController返回"your search term was test"
看着
Html.BeginForm("SearchQuery", "Search")
{
}
將您的文本字段放在該語句之間。 在那里也放一個按鈕。
就是這樣,基本上,周圍有很多例子...
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.