In my app I use auto complete text boxes. The problem is that for their source I have an action that returns me the items as JSON. Since I got only few items I do not want to call every time after the user press a key. I have the items in my model. How can 开发者_如何转开发I generate the JSON array from my model?
Something like: @Model.Categories.ToJsonAray(c=>c.Name) It is also good if you can tell me how to generate the json array from a list of strings.
@Html.Raw(Json.Encode(Model.Categories.Select(x => c.Name)))
UPDATED:
@{var myJson =new JavaScriptSerializer().Serialize(Model.Categories.Select(c=>c.Name));}
@myJson
精彩评论