Nur*_*ihu 14 c# asp.net asp.net-mvc asp.net-mvc-4
请我在MVC网站上工作,我有一个搜索页面和索引页面上的另一个搜索表单.当我从索引页面单击搜索按钮时,我想调用相同的搜索页面控制器.下面是我的按钮在索引页面上的方式.
    <span class="input-group-btn">
      <button class="btn btn-info" type="button" id="addressSearch"   
          onclick="location.href='<%: @Url.Action("List", "Search") %>'">
     Search</button></span>
列表是我的搜索搜索页面中的操作,搜索是控制器名称.当我单击上面的按钮时,它将返回表单中的url
http:// localhost:52050 / <%:%20/Search/List%20%>
显示不良请求.我怀疑它来自我的路由,我不知道如何实现这一点,请任何帮助将不胜感激.
以下是我的路由方式
 routes.MapRoute(
                name: null,
                url: "Page{page}",
                defaults: new { Controller = "Search", action = "List" }
                );
            routes.MapRoute(
            name: "Default",
            url: "{controller}/{action}/{id}",
            defaults: new
            {
                controller = "Home",
                action = "Index",
                id = UrlParameter.Optional
            }
            );
Ehs*_*jad 31
你正在混合razor和aspx语法,如果你的视图引擎是剃刀,只需这样做:
<button class="btn btn-info" type="button" id="addressSearch"   
          onclick="location.href='@Url.Action("List", "Search")'">
试试这个:
@Html.ActionLink("DisplayText", "Action", "Controller", route, attribute)
在你的代码应该是,
@Html.ActionLink("Search", "List", "Search", new{@class="btn btn-info", @id="addressSearch"})
| 归档时间: | 
 | 
| 查看次数: | 116126 次 | 
| 最近记录: |