我们在Global.asax.cs文件中有几条路线,但其中一条路线显然未被使用。ASP.Net MVC路线不能正常工作
// Search (NOT working).
routes.MapRoute(
"Search",
"search/{query}",
new { controller = "Search", action = "Index" });
// Homepage (I believe the problem could be here, but not sure).
routes.MapRoute(
"MainIndex",
"{language}",
new { controller = "Main", action = "Index", language = string.Empty });
当我们在搜索形式action属性“/搜索”的搜索,用户被发送到网页,并在地址栏中的URL是“/搜索?查询=例如+搜索” 。
形式action属性建立在使用此代码:
<form id="form1" action="<%= Url.Action("Index", "Search") %>">
似乎是正确的我,但动作的名称应该是“/搜索”,而不是“/搜索”,对不对?
我假设搜索路径在您的代码中的MainIndex路由之前列出*(正如您在自己的文章中所见),正确吗? – 2010-11-04 11:55:49
是的,赫克托。搜索路线列出了MainIndex路线__before__。 – 2010-11-04 14:11:02