加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

在ASP.NET MVC中搜索路径

发布时间:2020-12-16 04:06:56 所属栏目:asp.Net 来源:网络整理
导读:我的母版页中有一个简单的搜索表单和一个serach控制器和视图. 我正在尝试为字符串搜索术语“myterm”获取以下路由(例如): 根/搜索/ myterm 母版页中的表单: % using (Html.BeginForm("SearchResults","Search",FormMethod.Post,new { id = "search_form" }
我的母版页中有一个简单的搜索表单和一个serach控制器和视图.
我正在尝试为字符串搜索术语“myterm”获取以下路由(例如):
根/搜索/ myterm

母版页中的表单:

<% using (Html.BeginForm("SearchResults","Search",FormMethod.Post,new { id = "search_form" }))
                           { %>
                        <input name="searchTerm" type="text" class="textfield" />
                        <input name="search" type="submit" value="search" class="button" />
                        <%} %>

控制器行动:

public ActionResult SearchResults(string searchTerm){...}

我正在使用的路线:

routes.MapRoute(
          "Search","search/{term}",new { controller = "Search",action = "SearchResults",term = (string)null }
        );

routes.MapRoute(
          "Default","{controller}/{action}",new { controller = "Home",action = "Index" }
        );

无论我输入什么搜索词,我都会在没有搜索词的情况下获得网址“root / search”.

谢谢.

解决方法

您在beginform标记中使用了ID,在路线中使用了{term}.

两者需要匹配.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读