entity framework - ASP.NET with EF, how to autocomplete for text field to lookup from database -


i'm not sure how search - i'm using .net mvc 4 ef , have 2 simple models 1 many relationship - company , location. company can have many locations (eg, australia, us, canada etc)

i'd create form has text field user can enter in comma seperated list of locations, either autocopmlete existing locations, or add new location new ones.

ie, if start typing in "aus" , austrlia , austria both in locations database table, user should shown these choose - stackoverflow tags. if type in location doesn't exist in database table should create new record.

any pointers appreciated!

thanks, robbie

i read locations db prior rendering view , serialize them in json structure, or simple javascript array in rendered view. used autocomplete on client side of jquery (you use plugin, should simple enough make need. wouldn't complicate things employing kind of ajax call server triggered keydown event.

after form submitted, content of location field going text. so, you'd need location in database , if returns nothing, you'd need add prior saving company record.

i don't know exact model, code this:

var location = db.locations.find(l => l.locationname == valuethatwassubmitted); if (location == null)  {     // save new location }  // location exists, proceed rest (saving company, etc.) 

Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -