我正在使用以下 URL 构建一个简单的搜索引擎:
"/" - this is the homepage with the search textbox and submission button.
"/search?q=" - this is where the results will appear. The query is the q= parameter.
这是我的搜索控制器:
[HandleError]
public class SearchController : Controller {
public ActionResult Start() {
SearchModel model = new SearchModel();
return View( model );
}
/// <summary>Performs a search.</summary>
/// <param name="q">The search query.</param>
/// <param name="a">The search action ("I Feel Lucky", etc).</param>
/// <param name="page">The results page number.</param>
public ActionResult Search(String q, String a, String page) {
return View();
}
}
最后,这是我的路由表:
public static void RegisterRoutes(RouteCollection routes) {
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"SearchQuery",
"Search", // match "http://mysite.com/Search"
new { controller = "Search", action = "Search" }
);
routes.MapRoute(
"SearchStart", // Route name
"", // match "http://mysite.com/"
new { controller = "Search", action = "Start", id = UrlParameter.Optional } // Parameter defaults
);
}
但是,当我发出 HTTP 请求时,http://mysite.com/Search?q=foo
我得到一个 301 重定向到http://mysite.com/Search/
返回 404 的位置。我的SearchController
. Search
永远不会调用动作。
我需要做什么才能允许我正在做的事情?