开发者

MVC 3 JQuery UI autocomplete use model collection instead of action json result

开发者 https://www.devze.com 2023-04-11 16:59 出处:网络
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 callevery time after the

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
0

精彩评论

暂无评论...
验证码 换一张
取 消