asp.net mvc 4 - Autocomplete or create new object for model -
i'm trying implement similar so/gmail tag system: "try find matching tag or create new".
i have 2 simple classes:
public class item { [key] public int itemid { get; set; } [required] public string name { get; set; } public int categoryid { get; set; } public virtual category tag { get; set; } } public class category { [key] public int categoryid { get; set; } public string name { get; set; } }
the categorycontroller
implements autocompletecategory
-method returns json list of available categories:
public jsonresult autocompletecategory(string term) { var result = categoryrepository.all.where(category=> category.name.tolower().contains(term.tolower())).distinct(); return json(result, jsonrequestbehavior.allowget); }
i have jquery-script sends request method , displays matches.
now problem:
what need use in _createoredit
-view map edit-field model? represent category, bind categoryid, simple key, don't i?
and if edit field contains unknown category, how can create , bind model?
Comments
Post a Comment