jquery getJson not passing any values to controller

前端 未结 2 843
[愿得一人]
[愿得一人] 2021-01-02 14:52

I am trying to pass some text from a textbox to a controller to get JSON results like so

function invokeAction() {
        var searchText = $(\"#SearchTextBo         


        
2条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-02 15:25

    You will have to fix your route and replace {id} with {search} in order to get it to bind to the correct parameter - try something like this:

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

    If you don't want to do that, you can do it like this by specifying the parametername as a standard querystring paramter

    $.getJSON("/Home/Results?search=" + searchText,bindresults);
    

    that will fix the binding.

提交回复
热议问题