TwitterBootstrapMvc
TwitterBootstrapMvc copied to clipboard
Is it possible to pass an ID to TypeAhead controller?
I'd like to pass an configurable ID to my TypeAhead controller, e.g.
public ActionResult Index(long id, string term)
Is that possible?
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>