Send model to Jquery

我只是一个虾纸丫 提交于 2019-12-06 10:43:46

You need to conver you model to Json and use the converted object as a datasource:

<script>
$(dcoument).ready(function(){

var datasource = @ViewBag.JsonModel;
$('#MyTree').tree({ dataSource: dataSource });

});
</script>

Now you need to populate ViewBag.JsonModel in the action:

public ViewResult YourActionName()
{
 // your logic on getting model
ViewBag.JsonModel = //convert model to json using jsonserializer
}

Here is tree plugin example:

 // INITIALIZING TREE
var treeDataSource = new TreeDataSource({
data: [
{ name: 'Test Folder 1', type: 'folder', additionalParameters: { id: 'F1' } },
{ name: 'Test Folder 2', type: 'folder', additionalParameters: { id: 'F2' } },
{ name: 'Test Item 1', type: 'item', additionalParameters: { id: 'I1' } },
{ name: 'Test Item 2', type: 'item', additionalParameters: { id: 'I2' } }
],
delay: 400
});
$('#MyTree').tree({dataSource: treeDataSource}); 
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!