asp.net mvc - how to fetch multiple table data in a single linq query and bind it to a autocomplete search model -


i want autocomplete search google or facebook , want data 2 different table, using entity framework , mvc-4..i done far ajax here action

public actionresult autocomplete(string term) {     var model = _db.instructors                    .orderbydescending(u => u.id)                    .where(u => u.fullname.contains(term))                    .take(30)                    .select(u => new {                       label = u.firstname + " " + u.lastname                    });      return json(model, jsonrequestbehavior.allowget); } 

my js

$(function () {      var createautocomplete = function () {         var $input = $(this);          var options = {             source: $input.attr("data-otf-autocomplete"),             select: submitautocompleteform         };          $input.autocomplete(options);     };         $("input[data-otf-autocomplete]").each(createautocomplete); }); 

i want extract data 2 tables this

var model = _db.instructors                .orderbydescending(u => u.id)                .where(u => u.fullname.contains(term))                .take(30)                .select(u => new {                    label = u.firstname + " " + u.lastname                });  var model2 = _db.courses                 .orderbydescending(u => u.id)                 .where(u => u.title.contains(term))                 .take(30)                 .select(u => new {                     label = u.title                 });              return json(model2,model1 jsonrequestbehavior.allowget); 

i want display both instructors , courses in autocomplete list..please me out please

thus use same anonymous type, can concatenate instructors courses:

return json(model1.concat(model2), jsonrequestbehavior.allowget); 

Comments

Popular posts from this blog

html5 - What is breaking my page when printing? -

c# - must be a non-abstract type with a public parameterless constructor in redis -

ajax - PHP/JSON Login script (Twitter style) not setting sessions -