TwitterBootstrapMvc icon indicating copy to clipboard operation
TwitterBootstrapMvc copied to clipboard

Is it possible to pass an ID to TypeAhead controller?

Open codingarmadillo opened this issue 8 years ago • 1 comments

I'd like to pass an configurable ID to my TypeAhead controller, e.g.

public ActionResult Index(long id, string term)

Is that possible?

codingarmadillo avatar May 26 '16 14:05 codingarmadillo

Yes, please get latest as I've updated javascript file in order to handle this.

  • Use extension method .Source() to specify source function name:
@Html.Bootstrap().TextBox("MyInput").TypeAhead(new TypeAhead().Action("MyAction").Source("mySource"))
  • add this function name to the scripts on the page:
<script type="text/javascript">
    function mySource(term, process) {
        var url = $('#MyInput').data('url');
        var id = 1; // whatever the custom logic for that parameter

        return $.getJSON(url, { id: id, term: term }, function (data) {
            return process(data);
        });
    }
</script>

DmitryEfimenko avatar May 26 '16 18:05 DmitryEfimenko