如何调用从按钮点击控制器asp.net MVC 4 [英] How to call controller from the button click in asp.net MVC 4
问题描述
请我在MVC网站的工作,我有一个搜索页面和索引页面上的其他搜索表单。我想调用相同的搜索页面控制器,当我从索引页点击搜索按钮。下面是我的按钮是怎样的索引页。
<跨度类=输入组BTN>
<按钮类=BTN BTN-信息类型=按钮ID =addressSearch
的onclick =location.href ='<%:@ Url.Action(目录,搜索)%GT;'>
搜索< /按钮>< / SPAN>
列表是从搜索页面我的搜索操作和搜索是控制器的名字。当我点击上面的按钮,它的形式返回网址
的http://本地主机:52050 / <%:20%/搜索/列表%20%>
显示错误的请求。我从我的路由怀疑它,我不知道如何archieve这一点,请任何帮助将是AP preciated。
下面是我的路由怎么
routes.MapRoute(
名称:空,
网址:页面{PAGE},
默认:新{控制器=搜索,行动=名单}
);
routes.MapRoute(
名称:默认,
网址:{控制器} / {行动} / {ID}
默认:新
{
控制器=家,
行动=索引,
ID = UrlParameter.Optional
}
);
您在混合剃须刀和 ASPX 语法,如果你的视图引擎的剃须刀只是这样做:
<按钮类=BTN BTN-信息类型=按钮ID =addressSearch
的onclick =location.href ='@ Url.Action(目录,搜索),'>
Please i am working on MVC website, i have a Search page and another search form on index page. I want to call the the same search page controller when i click the search button from index page. Below is how my button is on the index page.
<span class="input-group-btn">
<button class="btn btn-info" type="button" id="addressSearch"
onclick="location.href='<%: @Url.Action("List", "Search") %>'">
Search</button></span>
List is my search Action from search page and Search is the controller name. When i click the button above, it returns url in the form
http://localhost:52050/<%:%20/Search/List%20%>
Showing bad request . I am suspecting its from my Routing , I am not sure how to archieve this, Please any help would be appreciated .
Below is how my Routing is
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
}
);
You are mixing razor and aspx syntax,if your view engine is razor just do this:
<button class="btn btn-info" type="button" id="addressSearch"
onclick="location.href='@Url.Action("List", "Search")'>
这篇关于如何调用从按钮点击控制器asp.net MVC 4的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!