我想从ViewBag.mytags到Javascript数组中的数据,但我没能avhice这
$(function () {
var sampleTags = new Array();
var array = @Html.Raw(Json.Encode(@ViewBag.mytags));
for(var i =0; i<array.length;i++){
sampleTags[i] = array[i];
}
$('#singleFieldTags').tagit({
availableTags: sampleTags,
singleField: true,
singleFieldNode: $('#mySingleField')
});
}
这是我的控制器
ViewBag.mytags = mp3.TagSuggestion();
这是我的模型
public IQueryable<string> TagSuggestion()
{
IQueryable<string> tabs = from s in db.tblTags select s.Title;
return tabs;
}