How to call controller from the button click in MVC 4


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") %>'">

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


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

                name: null,
                url: "Page{page}",
                defaults: new { Controller = "Search", action = "List" }

            name: "Default",
            url: "{controller}/{action}/{id}",
            defaults: new
                controller = "Home",
                action = "Index",
                id = UrlParameter.Optional

This question is tagged with c#

~ Asked on 2015-02-12 06:51:02

The Best Answer is


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")'">

~ Answered on 2015-02-12 06:57:43


Try this:

@Html.ActionLink("DisplayText", "Action", "Controller", route, attribute)

in your code should be,

@Html.ActionLink("Search", "List", "Search", new{@class="btn btn-info", @id="addressSearch"})

~ Answered on 2016-05-04 09:36:22

Most Viewed Questions: